0

I have a python selenium code to test a website. Now once the driver click on a link in the 1st tab, it opens it up in a new tab, but the focus stays on the previous tab, and I am not able to reference any elements in the new tab.

How can change the focus to the new?

Also both the tabs are open in the same browser and I am using Chrome browser

3

2 Answers 2

1

name each window if you are working with a few number of windows. using this chunk you can name and switch between tabs

window1= driver.window_handles[1]
driver.switch_to_window(window1)
Sign up to request clarification or add additional context in comments.

Comments

0

You can loop through the window handles, record the counts of window handles and switch with count - 1. Check below.

n = 0
for handle in driver.window_handles:
       n+=1
driver.switch_to_window(n-1)

If you encounter any difficulty, please paste your code for further elucidation.

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.