Reputation: 9475
I am creating a webdriver instance using selenium for some automation work. I am opening multiple tabs at a time and would like to know if there is a way to get the URLs of all the tabs open.
driver=webdriver.Chrome()
driver.current_url
The above code provides me with the URL of the first tab only. Another thing I tried was:
driver.window_handles[0].current_url
The above solution failed as window_handles()
returns a unicode object which does not contain current_url
I prefer not going through all the tabs actively in order to find the current_url
of each tab as it would disrupt the automation task at hand.
Upvotes: 6
Views: 11143
Reputation: 146630
You just need to loop through each window handle, switch to it and print the url
for handle in driver.window_handles:
driver.switch_to.window(handle)
print(driver.current_url)
Upvotes: 11