When I use selenium webdriver.Chrome().close(), does it will switch to the window before?

here is my code:

chrome = webdriver.Chrome()
chrome.switch_to.window(self.chrome.window_handles[1])
dosth...
chrome.close()
chrome.switch_to.window(self.chrome.window_handles[0])#

I want to know when I use the method 'close', do I need the last code line to switch to the window before?

Upvotes: 0

Views: 33

Answers (1)

Sabito
Sabito

Reputation: 5065

chrome.close() closed the webdriver object. Take a look at this post.

So,

chrome.close()
chrome.switch_to.window(self.chrome.window_handles[0])

is wrong. As this will close the webdriver. Instead:

chrome.switch_to.window(self.chrome.window_handles[0])
chrome.close()

is correct.

Upvotes: 1

Related Questions