I have a python code with selenium that opens multiple windows. I know how to switch between them numerically but is there a way to switch to a specific tab that's already open by searching the URL?
In Java browser.switchWindow(urlOrTitleToMatch)
can do the trick,
where urlOrTitleToMatch
is your URL string or a regular expression. https://webdriver.io/docs/api/browser/switchWindow.html
In Python it looks like you have to loop through all windows until you find a URL match.
import re
def switchWindow(URL, browser):
for window in browser.getWindowHandles():
browser.switch_to_window(window)
if re.search(URL, browser.current_url):
break;
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.