【发布时间】:2017-10-21 06:37:39
【问题描述】:
我正在使用 Selenium 对 Chrome 进行一些检查。 我会自动浏览到“chrome://flags/#enable-quic”,然后在下拉菜单中(自动)选择“启用”。 如下所述,必须重新启动才能使更改生效。 我想在重新启动的新窗口上打开一个新选项卡来做更多的事情。
代码片段:
browser = webdriver.Chrome()
browser.get("chrome://flags/#enable-quic")
browser.find_element_by_xpath("//*[@id='enable-quic']/table/tbody/tr/td/div[1]/div/div[2]/select/option[2]").click() #Select "Enable"
time.sleep(5)
browser.find_element_by_xpath("//*[@id='flagsTemplate']/div[5]/button").click() #Click relaunch
time.sleep(5)
browser.execute_script("window.open('https://www.gmail.com');") #Exception after this line
我得到的例外是:
selenium.common.exceptions.NoSuchWindowException: Message: no such window: window was already closed
有人知道如何处理这个问题吗?
谢谢
【问题讨论】:
标签: python selenium selenium-webdriver automated-tests