Warning: session_start(): open(/var/cpanel/php/sessions/ea-php72/sess_3d14f0125062f576aa58533c9ff00a1a, O_RDWR) failed: No space left on device (28) in/home/mytectra/public_html/community/wp-content/plugins/wpforo/wpf-includes/class-notices.phpon line16

Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/ea-php72) in/home/mytectra/public_html/community/wp-content/plugins/wpforo/wpf-includes/class-notices.phpon line16
How to switch different browser tabs using Python Selenium – Python – Community – myTectra Forum
How to switch diffe...
Notifications
Clear all

How to switch different browser tabs using Python Selenium

RSS

(@abhijith)
Noble Member
Joined: 1 year ago
帖子:1350
12/05/2021 12:44 pm

How to switch different browser tabs using Python Selenium?


Quote
(@sathish)
Member Moderator
Joined: 1 year ago
帖子s: 1391
12/05/2021 12:45 pm

you can use the following lines of code to switch different browser tabs using Python Selenium Webdriver:

import selenium.webdriver as webdriver import selenium.webdriver.support.ui as ui from selenium.webdriver.common.keys import Keys from time import sleep browser = webdriver.Firefox() browser.get('https://www.google.com?q=python#q=python') first_result = ui.WebDriverWait(browser, 15).until(lambda browser: browser.find_element_by_class_name('rc')) first_link = first_result.find_element_by_tag_name('a') main_window = browser.current_window_handle first_link.send_keys(Keys.CONTROL + Keys.RETURN) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB) browser.switch_to_window(main_window) sleep(2) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') browser.switch_to_window(main_window)

ReplyQuote
Share:
Baidu