Reputation: 2673
I'm doing remote web crawling and scraping, and hoping not to reload a new browser window for every link on one page.
The problem is that new tabs are not opening up with my Firefox web driver.
Here's what I've tried:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from pyvirtualdisplay import Display
# launch our headless display
display = Display(visible=0, size=(800, 600))
display.start()
# launch our web driver and get a page
browser = webdriver.Firefox()
browser.get("http://www.google.com/")
# try to open a new tab
ActionChains(browser).key_down(Keys.CONTROL).send_keys("t").key_up(Keys.CONTROL).perform()
# this should print 2, but it prints 1, because new tab not opened
print len(browser.window_handles)
# clean up everything
browser.quit()
display.stop()
Specifications:
Upvotes: 0
Views: 530
Reputation: 2673
Based on this response from a Selenium developer, new tabs in Firefox are not supported as of August 2015. He suggested exploring Marionette but currently its dependencies cause more trouble than it's worth, at least for my use case. His solution is to just use new windows (driver.execute_script("window.open()")
), instead of new tabs.
Upvotes: 1