You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
It took me quite a spin to figure this one out.
Issue:
Opening a link in a new tab issue (Multitab) - webdriver with Python
What steps will reproduce the problem?
1.elem = browser.find_element_by_xpath("/html/body/div[2]/div[4]/div/a")
2.elem.send_keys(Keys.CONTROL + Keys.RETURN + "2")
3.for handle in browser.window_handles:
print "Handle is:" + str(handle)
What is the expected output? What do you see instead?
Expect: Either multiple handles or being able to work with the current focused tab
due to using (Keys.CONTROL + "2")
Actual Output: one handle entry only. any code after that won't work on the tab
Selenium version: 2.32.0
OS:Windows 7
Browser:Firefox
Browser version:20.0.1
Solution:
It seems for some reason although the handle entry is still within the webdriver but
the window has lost sync some how. The solution is to switch the window after opening
the new tab. Here is the code with the fix in it
elem = browser.find_element_by_xpath("/html/body/div[2]/div[4]/div/a") #href link
time.sleep(2)
elem.send_keys(Keys.CONTROL + Keys.RETURN + "2") #Will open a second tab
#solution for the 2nd issue is here
for handle in browser.window_handles:
print "Handle is:" + str(handle) #only one handle number
browser.switch_to_window(handle)
time.sleep(3)
#Switch the frame over. Even if you have switched it before you need to do it again
browser.switch_to_frame("Frame")
"""now this is how you handle closing the tab and working again with the original tab"""
#again switch window over
elem.send_keys(Keys.CONTROL + "w")
for handle in browser.window_handles:
print "HandleAgain is:" + str(handle) #same handle number as before
browser.switch_to_window(handle)
#again switch frame over if you are working with one
browser.switch_to_frame("Frame")
time.sleep(3)
#doing a second round/tab
elem = browser.find_element_by_xpath("/html/body/div[2]/div[4]/div/a") #href link
time.sleep(2)
elem.send_keys(Keys.CONTROL + Keys.RETURN + "2") #open a 2nd tab again
"""Got it? find the handle, switch over the window then switch the frame"""
Reported by logicallayer on 2013-04-30 00:00:46
The text was updated successfully, but these errors were encountered:
Selenium does not support tabs. It is recommended to open links in new windows if you
need to work with several pages at the same time.
Do you really need to open a link in a new tab instead of a new window? Does this affect
the behaviour of the application under test?
Tabs would be great to support, also there is so much misleading material on the Internet
that says that tabs are part of window handling. It took me quite some time to find
out why only one window shows in the windows list when I have multiple tabs open.
Originally reported on Google Code with ID 5572
Reported by
logicallayer
on 2013-04-30 00:00:46The text was updated successfully, but these errors were encountered: