Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Scraping
#1
Hello guys,

I would like to open a new tab in my opened browser and then read the content, I have tried with Selenium but I cannot find the way to open a new tab in the opened browser as I mentioned.

Thank you in advance
Reply
#2
What do u want exactly? U can do it with selenium probably. Why do u need to open a new tab? U can use "get" method again ?
Reply
#3
you should look at:
web scraping part 1
web scraping part 2
Reply
#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


Forum Jump:

User Panel Messages

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