问题
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.
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.
I now move to a Centos-7 box, and hit a problem
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
I am using
- Selenium: 3.141.59
- Gecko: geckodriver 0.24.0 ( 2019-01-28)
- Firefox: Mozilla Firefox 60.8.0
I have Xvfb installed and running.
My code simply calls
m_driver = new FirefoxDriver();
which I believe to be the current idiom.
I have added
JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"
to my tomcat.conf
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.
回答1:
I think you were pretty close. Though the following line in tomcat.conf
looks perfect:
JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"
But I am still not sure if -Dwebdriver.firefox.driver=/usr/bin/firefox
is a requirement for you.
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.
So dropping -Dwebdriver.firefox.driver=/usr/bin/firefox
will solve the issue.
Update
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:
- 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
There is no need for
xvfb-run
anymore if you setMOZ_HEADLESS=1
as follows:$ export MOZ_HEADLESS=1 # this way you only have to set it once
You can find a detailed discussion in How to make firefox headless programmatically in Selenium with python?
- 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.
来源:https://stackoverflow.com/questions/57577576/selenium-webdriver-firefox-centos-unable-to-find-a-matching-set-of-capabiliti