[英]How to open new website via selenium and than open new tab and close new tab and work with first tab in python
我为此计划尝试使用硒网络驱动程序“我通过示例网站上的硒网络驱动程序打开了新链接,称为scene-rls
,并在此站点中进行了一些工作,在我打开新标签页以打开google.com
之后,然后进行了一些工作,关闭google
标签,然后返回scene-rls
标签,并在scene-rls
标签上进行新工作,但是在我的代码中,当我打开google.com
并关闭该标签并返回到scene-rls
标签时,代码返回这样的错误:
selenium.common.exceptions.NoSuchWindowException: Message: no such window: window was already closed
我的代码是:
Regular_part = "Ambulance Australia S02E05 WEB H264-FLX"
driver =
webdriver.Chrome(executable_path=r'C://chromdriver//chromedriver.exe')
x = True
while x:
driver.get('http://scene-rls.net/?s='+Regular_part+'&submit=Find')
time.sleep(5)
driver.find_element_by_xpath('/html/body/div/div[1]/div[2]/h1/a').click()
print("Opent new tab")
driver.execute_script("window.open ('https://google.com', 'new window')")
time.sleep(3)
print("back scn tab")
driver.switch_to_window(driver.window_handles[0])
time.sleep(3)
print("back google tab")
driver.switch_to_window(driver.window_handles[1])
driver.execute_script("window.close ('https://google.com', 'new window')")
z = input(":::")
if z == "y":
x = True
else:
x = False
关闭窗口后,您必须再次切换回上一个窗口。
driver.execute_script("window.close ('https://google.com', 'new window')")
driver.switch_to.window(driver.window_handles[0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.