简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM