Block ads that appear on the current web page.
(self)
| 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.""" |