Selenium WebDriver,Firefox,Centos无法找到匹配的功能集 [英] Selenium WebDriver, Firefox, Centos, unable to find a matching set of capabilities
问题描述
我有一个使用Selenium WebDriver来控制FireFox的应用程序.它在Tomcat下作为Web应用程序运行-是的,这有点奇怪,但是这样做有充分的理由.
I have an application that uses Selenium WebDriver to control FireFox. It runs as a Web Application under Tomcat - yes, this is a bit of an odd architecture, but there are good reasons for doing this.
我已经在MacBook上对其进行了测试,并且运行良好.我的代码叫WebDriver,WebDriver叫gecko,Firefox运行,一切都很好.
I've been testing this on my MacBook and it's been working well. My code calls WebDriver, WebDriver calls gecko, Firefox runs, all is good.
我现在移至Centos-7盒,并遇到问题
I now move to a Centos-7 box, and hit a problem
org.openqa.selenium.SessionNotCreatedException:无法找到 匹配的功能集Build info:version:'3.141.59', 版本:'e82be7d358',时间:'2018-11-14T08:17:03'系统信息: 主机:'xxx',ip:'a.b.c.d',操作系统名称:'Linux',os.arch:'amd64', os.version:'3.10.0-693.el7.x86_64',java.version:'1.8.0_222'驱动程序 信息:driver.version:FirefoxDriver
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host:'xxx', ip: 'a.b.c.d', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.el7.x86_64', java.version: '1.8.0_222' Driver info: driver.version: FirefoxDriver
我正在使用
- 硒:3.141.59
- Gecko:geckodriver 0.24.0(2019-01-28)
- Firefox:Mozilla Firefox 60.8.0
我已经安装并正在运行Xvfb.
I have Xvfb installed and running.
我的代码只需调用
m_driver = new FirefoxDriver();
我相信这是当前的成语.
which I believe to be the current idiom.
我已添加
JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"
到我的tomcat.conf
to my tomcat.conf
我从较旧的Firefox和Gecko版本中看到了对此类问题的引用,并表明这可能是版本问题,但据我所知,我掌握的是最新版本.
I see references to this kind of problem from older versions of Firefox and Gecko, and an indication it may be a version problem, but as far as I can tell I'm at the latest versions of everything.
请提出修复建议或获取一些诊断信息.
Suggestions for fix or getting some diagnostics please.
推荐答案
我认为您非常接近.尽管tomcat.conf
中的以下行看起来很完美:
I think you were pretty close. Though the following line in tomcat.conf
looks perfect:
JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"
但是我仍然不确定-Dwebdriver.firefox.driver=/usr/bin/firefox
是否对您来说是必需的.
But I am still not sure if -Dwebdriver.firefox.driver=/usr/bin/firefox
is a requirement for you.
按照类FirefoxDriver.SystemProperty 的值webdriver.firefox.driver
指的是常量字段
As per Class FirefoxDriver.SystemProperty the value of webdriver.firefox.driver
refers to the Constant Field DRIVER_XPI_PROPERTY which is the System property that defines the location of the webdriver.xpi
browser extension to install in the browser. If not set, the prebuilt extension bundled with this class will be used. Unless absolutely necessary this Constant Field must be left untouched.
因此删除-Dwebdriver.firefox.driver=/usr/bin/firefox
即可解决问题.
So dropping -Dwebdriver.firefox.driver=/usr/bin/firefox
will solve the issue.
有关您的用例的更多详细信息将有助于我们以更好的方式调试问题.但是,正如您提到的那样, Xvfb
已安装并正在运行,您需要注意以下两个事实:
A bit more details about your usecase would have helped us to debug the issue in a better way. However as you have mentioned Xvfb
is installed and running you need to take care of a couple of facts as mentioned below:
- 确保如果在没有显示 的系统上运行 Firefox ,则必须使用 headless模式.
-
无头模式在 GeckoDriver v0.24.0 中的正确用法是:
- Ensure that if you are running Firefox on a system with no display you have to use headless mode.
The correct usage of headless mode with GeckoDriver v0.24.0 is:
options.headless = True
如果按如下方式设置MOZ_HEADLESS=1
,则不再需要xvfb-run
:
There is no need for xvfb-run
anymore if you set MOZ_HEADLESS=1
as follows:
$ export MOZ_HEADLESS=1 # this way you only have to set it once
- If you have changed your system path, take a System Reboot.
- Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.- Always execute your @Tests as a non-root user.
这篇关于Selenium WebDriver,Firefox,Centos无法找到匹配的功能集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!