gpt4 book ai didi

python - 无法找到与 firefox、python、selenium 匹配的功能集(使用 vagrant)

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:13 35 4
gpt4 key购买 nike

使用:Selenium 3.4.3、Firefox 54、geckodriver 0.17.0

我在使用 precise64 框的虚拟机上尝试在 python 中创建 Firefox webdriver 时收到此错误消息。我的笔记本电脑运行的是 Mac OS Sierra。这是我的错误信息:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

我正在运行 browser = webdriver.Firefox()。我已经尝试在我的 vagrant 目录中指定 geckodriver 可执行文件的路径,即 browser = webdriver.Firefox('/vagrant/'),但它仍然无法找到一组匹配的能力。我的 geckodriver 与我尝试运行的脚本位于同一目录中。我也将 vagrant 文件夹添加到我的路径中。根据我看到的各种帖子,我相信我使用的所有东西都是最新的 this one .

有谁知道为什么我会遇到这个问题?提前谢谢你。

最佳答案

万一其他人遇到这个问题:问题似乎是虚拟机没有显示,并且要么需要像 pyvirtualbox 这样的虚拟显示,要么像 phantomJS 这样的 headless 浏览器。

编辑:我正在添加有关如何实现我列出的两个解决方案的示例。通常,您解决此问题所采用的方法取决于您有哪些限制。最简单的方法是不使用虚拟机,但如果您确实需要使用 VM,则需要采用我上面概述的两种方法之一。

# PHANTOM JS SOLUTION
from selenium import webdriver
driver = webdriver.PhantomJS() # assuming your phantomJS driver is in your path already
driver.get("https://www.google.com")
driver.quit() # only use this when done with automation

# PYVIRTUALBOX SOLUTION
from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1920, 1080)).start()
driver = webdriver.Firefox()
driver.get("https://www.google.com")
display.close() # use this only once you are finished with automation
driver.quit()

关于python - 无法找到与 firefox、python、selenium 匹配的功能集(使用 vagrant),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44786975/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com