2

I want to be able to manage several webdriver tabs. I want to get the ID of each when I make it, but I can only find the window ID (it must be for the entire window, since changing tabs it stays the same):

In [17]: main_window = browser.current_window_handle

In [18]: main_window
Out[18]: u'{7606f3fb-ece7-4c11-b951-d743684b0987}'

# move to the other tab
In [19]: browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL+Keys.TAB)

In [20]: main_window = browser.current_window_handle

# no difference
In [21]: main_window
Out[21]: u'{7606f3fb-ece7-4c11-b951-d743684b0987}'

How can I differentiate between my different tabs when I get several running in one window? Thank you

codyc4321
  • 9,014
  • 22
  • 92
  • 165

1 Answers1

1

1.You have to store window_handles in a variable. Each tab has its own window handle id.

tabHandles = driver.window_handles

2.Switch to other tabs by

driver.switch_to_window(tabHandles[0])  #switch to a tab
driver.switch_to_window(tabHandles[1])  #switch to a tab
Buaban
  • 5,029
  • 1
  • 17
  • 33
  • I should have clarified though, I want to get the tab ID of a new tab as I open it. This can get very difficult to track if I open and close tabs, as in if I have 5 tabs, the 5th one is at tabHandles[4]. but if I close a tab, now the 5th one is at tabHandles[3]. I want a foolproof longterm way to keep track of tabs as I work – codyc4321 Feb 24 '16 at 03:10