2

I have a situation where I click on a button that opens up a new browser Window. Is there any way to connect to the newly opened window? And work with it, then return back to original browser (first window).

Thank you.

After some thorough investigation on the net I managed to get some of the code working

Currentwindow = driver.window_handles
Likebutton = driver.find_element_by_css_selector(".single_like_button .btn3").click()
newwindow = driver.window_handles
newwindow = list(set(newwindow) - set(Currentwindow))[0]
driver.switch_to.window(newwindow)
driver.find_element_by_id("watch-like").click()
driver.implicitly_wait(5)
driver.close()

Problem is the command driver.implicitly_wait(5) doesn't work for some reason and the page automatically closes which is not something I want. How do I get it working?

2 Answers 2

4
driver.switch_to.window(handle)

switches the focus to the specified window. handle can be a name or window handle.

You can use

driver.window_handles

to find a list of window handles.

There are also these functions which you may find useful:

driver.switch_to.active_element     
driver.switch_to.default_content    
driver.switch_to.parent_frame   
driver.switch_to.alert 
driver.switch_to.frame 
driver.switch_to.window
Sign up to request clarification or add additional context in comments.

1 Comment

Updated with another issue
1

too late for you , but maybe this will help someone

driver.implicitly_wait(5)

this command wait , while the page is loaded or 5 sec. If it will be loaded in 1 sec , then

driver.close() 

Run after 1 second . If it be loaded in 7 sec , then

driver.close() 

Run after 5 sec

You may use

import time

time.sleep(5)

It will wait exactly 5 sec anyway

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.