Failed to start Firefox browser from Selenium Webdriver version 3.4.0

I had a problem with the fact that I cannot start firefox from Selenium Webdriver version 3.4.0 from my Windows operating system (Windows 7), which is 64-bit. Currently, firefox version 52.0.2 is installed on my machine. I also added the selenium jar library files to the library, but an error appears.

My code is:

package sanity;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login
{
        public static void main(String[] args)    
        {
            WebDriver driver=new FirefoxDriver();    
            driver.close(); 
        }
}

Error:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
    at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at sanity.Login.main(Login.java:18)

After that, I loaded the GeckoDriverService into the SeleniumHQ.org form and started under the code, now after starting under the updated code using the Geckodriver path, the Firefox browser starts, but does not close automatically. I also get a message in the console.

The code:

package sanity;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login 
{

        public static void main(String[] args) 
        {

          String Firefoxdriverpath="C://Users//Ashish//Downloads//geckodriver-v0.16.0-win64//geckodriver.exe";

            System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);

            WebDriver driver=new FirefoxDriver();

            driver.close(); 
        }

}

Console:

    1492944489305   geckodriver INFO    Listening on 127.0.0.1:12059
1492944489973   geckodriver::marionette INFO    Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1492944491445   addons.manager  ERROR   startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"  data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()@resource://gre/modules/AddonManager.jsm:700 < AddonManagerInternal.startup()@resource://gre/modules/AddonManager.jsm:870 < this.AddonManagerPrivate.startup()@resource://gre/modules/AddonManager.jsm:3033 < amManager.prototype.observe()@resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1677: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1492944492505   Marionette  INFO    Listening on port 50231
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2585: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
Apr 23, 2017 4:18:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

Please help.

Thanks Ashish Jain

+4
8

, "driver.quit" "driver.close".

" Javascript (AddonManager)" , , - , , :)

0

Firefox?

FireFox geckodriver

0

"Javascript error (AddonManager)"... , , . . : geckodriver v.0.16.0 " Selenium 3.4 " ( ). 3.3.1 . 21 3.4.0. , Selenium. - , .

0

,

String Firefoxdriverpath="C://Users//Ashish//Downloads//geckodriver-v0.16.0-win64//geckodriver.exe";
System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);  
driver.close(); 

, , .

0

. :

String Firefoxdriverpath i.e "/"

. String Firefoxdriverpath="C:/Utility/BrowserDrivers/geckodriver.exe";

i.e "\\"

. String Firefoxdriverpath="C:\\Utility\\BrowserDrivers\\geckodriver.exe";

, .

0

. driver.quit(); driver.close();

0

, , , , 3.4 -

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", false); // true gives that Javascript error (AddonManager is not initialized)
0

Firefox: 45.9.0; Selenium 3.4.0 Gecko: 16.1.

Solution: upgrade to gecko 16.0 and use: System.setProperty (" webdriver.firefox.marionette ", "Path");

Hope this helps.

0
source

Source: https://habr.com/ru/post/1675438/


All Articles