xalen8242
xalen8242

Reputation: 31

How can I get the titles of each window_handles item in python selenium

Basically, as the title says, I want to get the title information from driver.window_handles[x]. I tried doing

driver.window_handles[0].title

But that didn't work.

Printing the array of window_handles gives a bunch of numbers for each item, so I figure something like

driver.something.window(driver.window_handles[0])).title

May work. My thought process being that switch_to.window() can read this array, so maybe there is another bit of code that can read this information and get me the title of the tab.

Any help would be appreciated

Edit: Should have mentioned that I'm trying to do this without switching to different tabs. So, I want to get say tab 3's title without switch from tab 1.

Upvotes: 2

Views: 2490

Answers (1)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

for handle in driver.window_handles:
    driver.switch_to_window(handle)
    print(driver.title)

Switch to handle and print its title. No other way I know of

Upvotes: 1

Related Questions