1

My question is that I excepted main tab to be closed after the execution of last of code as the focus should be on that tab after i closed the second tab. But instead I got this error, selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed from unknown error: web view not found see the code below with comments

driver = webdriver.Chrome(path)
actions_chain = ActionChains(driver)
driver.get(url)
time.sleep(10)

title_click = driver.find_element_by_xpath('//div[@data-testid = "listing-card-title"]')

actions_chain.click(title_click).perform()
#using action_chains instance in order to click
#that click takes me to the description page in the second tab

driver.switch_to.window(driver.window_handles[1])
#switch the browser focus to second tab

driver.close()
#closing the second tab
#After closing the second tab, I only left with one main tab and the browser focus should be on that one main tab without explicitly shifting to that tab

driver.close()
so the main tab also gets closed.
Ali Haider
  • 25
  • 4

1 Answers1

0

I think after you close the second tab you have to back to main tab in code like that :

driver = webdriver.Chrome(path)
actions_chain = ActionChains(driver)
driver.get(url)
time.sleep(10)

title_click = driver.find_element_by_xpath('//div[@data-testid = "listing-card-title"]')

actions_chain.click(title_click).perform()
#using action_chains instance in order to click
#that click takes me to the description page in the second tab

driver.switch_to.window(driver.window_handles[1])
#switch the browser focus to second tab

driver.close()

#closing the second tab
driver.switch_to.window(driver.window_handles[0])
# Your code here
driver.close()