Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Scraping
#4
# Opens a new tab
driver.execute_script("window.open()")
 
# Switch to the newly opened tab
driver.switch_to.window(driver.window_handles[1])
 
# Navigate to new URL in new tab
driver.get("https://google.com")
# Run other commands in the new tab here
 
You're then able to close the original tab as follows
 
# Switch to original tab
driver.switch_to.window(driver.window_handles[0])
 
# Close original tab
driver.close()
 
# Switch back to newly opened tab, which is now in position 0
driver.switch_to.window(driver.window_handles[0])
 
Or close the newly opened tab
 
# Close current tab
driver.close()
 
# Switch back to original tab
driver.switch_to.window(driver.window_handles[0])
Recommended Tutorials:
Reply


Messages In This Thread
Web Scraping - by alexcuba75 - Aug-02-2020, 06:06 PM
RE: Web Scraping - by Nomatter - Aug-02-2020, 06:17 PM
RE: Web Scraping - by Larz60+ - Aug-02-2020, 09:04 PM
RE: Web Scraping - by metulburr - Aug-03-2020, 01:52 AM

Forum Jump:

User Panel Messages

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