-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSelenium_tabs_chrome.py
More file actions
29 lines (20 loc) · 913 Bytes
/
Copy pathSelenium_tabs_chrome.py
File metadata and controls
29 lines (20 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-agent=...")
driver = webdriver.Chrome(executable_path="/PycharmProjects/selenium_python/chromedriver/chromedriver",
options=options)
try:
driver.get("https://www...")
# driver.implicitly_wait(5)
# print(driver.window_handles) # driver.window_handles - return a list with opened tabs
# print(f"Currently URL is: {driver.current_url}") # checking a current URL
driver.switch_to.window(driver.window_handles[1]) # go to second tab
print(f"Currently URL is: {driver.current_url}") # checking a current URL
driver.close()
driver.switch_to.window(driver.window_handles[0]) # go back to first opened tab
print(f"Currently URL is: {driver.current_url}")
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()