MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / ad_block

Method ad_block

seleniumbase/fixtures/base_case.py:7466–7484  ·  view source on GitHub ↗

Block ads that appear on the current web page.

(self)

Source from the content-addressed store, hash-verified

7464 self.execute_script(script)
7465
7466 def ad_block(self):
7467 """Block ads that appear on the current web page."""
7468 from seleniumbase.config import ad_block_list
7469
7470 self.__check_scope() # Using wait_for_RSC would cause an infinite loop
7471 for css_selector in ad_block_list.AD_BLOCK_LIST:
7472 css_selector = re.escape(css_selector) # Add "\\" to special chars
7473 css_selector = self.__escape_quotes_if_needed(css_selector)
7474 script = (
7475 """var $elements = document.querySelectorAll('%s');
7476 var index = 0, length = $elements.length;
7477 for(; index < length; index++){
7478 $elements[index].remove();}"""
7479 % css_selector
7480 )
7481 try:
7482 self.execute_script(script)
7483 except Exception:
7484 pass # Don't fail test if ad_blocking fails
7485
7486 def show_file_choosers(self):
7487 """Display hidden file-chooser input fields on sites if present."""

Callers 15

block_adsMethod · 0.95
__ad_block_as_neededMethod · 0.95
blokkeer_advertentiesMethod · 0.80
annonces_de_blocMethod · 0.80
bloccare_gli_annunciMethod · 0.80
bloquear_anunciosMethod · 0.80
광고_차단Method · 0.80
ブロック広告Method · 0.80
阻止广告Method · 0.80
bloquear_anúnciosMethod · 0.80
test_geolocationMethod · 0.80

Calls 3

__check_scopeMethod · 0.95
execute_scriptMethod · 0.95

Tested by 6

test_geolocationMethod · 0.64
test_google_tourMethod · 0.64
test_google_tourMethod · 0.64
test_google_tourMethod · 0.64
test_google_tourMethod · 0.64
test_google_tourMethod · 0.64