Reputation: 77
i tried to work with selenium web driver for this plan " i open new link via selenium web driver on example website called scene-rls
and do some work in this site and after i open new tab to open google.com
then do some works and close the google
tab and back to scene-rls
tab and do new work on the scene-rls
tab , but in my code when i open google.com
and close the tab and back to the scene-rls
tab the code return error like this:
selenium.common.exceptions.NoSuchWindowException: Message: no such window: window was already closed
and my code is :
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
Upvotes: 0
Views: 197
Reputation: 33384
After closing to window you have to Switch back to previous window again.
driver.execute_script("window.close ('https://google.com', 'new window')")
driver.switch_to.window(driver.window_handles[0])
Upvotes: 1