繁体   English   中英

Ubuntu上的Python Selenium Firefox:新选项卡不起作用

[英]Python Selenium Firefox on Ubuntu: New Tabs Not Working

我正在进行远程Web爬网和抓取,希望不要为一页上的每个链接重新加载新的浏览器窗口。

问题是我的Firefox Web驱动程序没有打开新标签页。

这是我尝试过的:

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()

规格:

  • Ubuntu 14.04.2
  • Python 2.7.6
  • 硒2.47.1
  • PyVirtualDisplay 0.1.3

根据Selenium开发人员的回复 ,截至2015年8月,Firefox中不支持新选项卡。他建议研究Marionette,但目前,其依赖关系会带来更多麻烦,至少在我的用例中。 他的解决方案是仅使用新窗口( driver.execute_script("window.open()") ),而不是新选项卡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM