2

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.

1 Answer 1

2

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.