Issue
My Code do what it should do until it reach the point when a button is clicked and a second PDF window opens. I try to switch to the PDF window to close it but it does not work, my Code after the button is clicked looks like:
while len(browser.window_handles) < 2:
sleep(1)
browser.switch_to_window(browser.window_handles[1])
sleep(0.5)
browser.close()
sleep(0.5)
browser.switch_to_window(browser.window_handles[0])
With this Code i get the error message: AttributeError: 'WebDriver' object has no attribute 'switch_to_window'
I already used this code in another project with a older selenium version and there it works fine.. In my current project I use selenium 4.5.0. I am happy for any hint you guys can make.
Solution
Selenium 4 no more supports switch_to_window
method.
switch_to.window
should be used instead, as following:
browser.switch_to.window(browser.window_handles[0])
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.