Frage

I'm currently writing a visual test that require adblock to be installed to stop some ads from ruining the test. However when I run the Chromedriver with the adblock extension installed it brings up the successfully installed adblock tab. This tab screws up my screenshots because the driver is working in a previous tab that opens. Is there any way to stop the adblock tab from opening or prevent the black screenshot from happening? Here is the initialization for the driver.

def setUp(self):
    chrome_options = Options()
    chrome_options.add_extension('AdBlock_v2.6.4.crx')
    self.driver = webdriver.Chrome('chromedriver', port=0, chrome_options=chrome_options)
    self.driver.implicitly_wait(15)
War es hilfreich?

Lösung

handles = self.driver.window_handles
self.driver.switch_to_window(handles[-1])

seems to be the best way to handle it. It simply tells the driver to switch to the tab which is considered a window. I feel silly for trying to find a more complex solution

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top