Selenium WebDriver, Firefox, Centos, unable to find a matching set of capabilities

前端 未结 1 499
梦谈多话
梦谈多话 2020-12-12 04:26

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 g

相关标签:
1条回答
  • 2020-12-12 04:39

    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 set MOZ_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() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
    • Always execute your @Tests as a non-root user.
    0 讨论(0)
提交回复
热议问题