【问题标题】:Python Selenium Firefox on Ubuntu: New Tabs Not WorkingUbuntu 上的 Python Selenium Firefox:新标签不起作用
【发布时间】:2015-08-30 14:50:00
【问题描述】:

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

问题是我的 Firefox 网络驱动程序无法打开新标签页。

这是我尝试过的:

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

【问题讨论】:

    标签: python firefox ubuntu selenium pyvirtualdisplay


    【解决方案1】:

    基于this response from a Selenium developer,截至 2015 年 8 月,Firefox 中的新选项卡不受支持。他建议探索Marionette,但目前它的依赖关系带来的麻烦多于其价值,至少对于我的用例而言。他的解决方案是只使用新窗口 (driver.execute_script("window.open()")),而不是新标签。

    【讨论】:

      猜你喜欢
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2020-04-09
      • 2018-08-25
      • 2017-07-09
      • 2014-01-01
      • 2018-09-24
      相关资源
      最近更新 更多