codyc4321
codyc4321

Reputation: 9672

how to get the different IDs for different webdriver tabs

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

Upvotes: 2

Views: 361

Answers (1)

Buaban
Buaban

Reputation: 5137

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

Upvotes: 1

Related Questions