Python Forum
Need Help Opening A New Tab in Selenium
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help Opening A New Tab in Selenium
#2
this will open a new tab in chrome, set focus, close tab, then close the final tab
from selenium import webdriver
import time

driver = webdriver.Chrome('/home/metulburr/chromedriver')
driver.get('https://python-forum.io/Thread-Need-Help-Opening-A-New-Tab-in-Selenium')
# Open a new window
# This does not change focus to the new window for the driver.
driver.execute_script("window.open('');")
time.sleep(3)
# Switch to the new window
driver.switch_to.window(driver.window_handles[1])
driver.get("http://stackoverflow.com")
time.sleep(3)
# close the active tab
driver.close()
time.sleep(3)
# Switch back to the first tab
driver.switch_to.window(driver.window_handles[0])
driver.get("http://google.se")
time.sleep(3)
# Close the only tab, will also close the browser.
driver.close()
Recommended Tutorials:
Reply


Messages In This Thread
RE: Need Help Opening A New Tab in Selenium - by metulburr - Jan-14-2018, 11:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Web Page not opening while web scraping through python selenium sumandas89 4 10,221 Nov-19-2018, 02:47 PM
Last Post: snippsat
  Selenium opening pdf in new window test 6 11,177 Sep-15-2018, 07:55 PM
Last Post: test
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,717 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020