Reputation: 51
I am facing an issue wherein I am unable to launch 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 have also added selenium jar files to the library, still it is showing error.
My code:
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 this, I downloaded GeckoDriverService form SeleniumHQ.org and ran below code, now after running below updated code with the Geckodriver path, firefox browser is getting launched but not closing automatically. Also I am getting some message in console.
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
Kindly help.
Thanks, Ashish Jain
Upvotes: 3
Views: 12843
Reputation: 186
Got this error when using Firefox version: 45.9.0; Selenium 3.4.0 and Gecko driver: 16.1.
Solution: Downgrade to gecko 16.0 and use: System.setProperty("webdriver.firefox.marionette", "Path");
Hope this helps.
Upvotes: 0
Reputation: 11
I had the similar issue but finally got it solved by this small code below changed for selenium 3.4 capability-
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false); // true gives that Javascript error (AddonManager is not initialized)
Upvotes: 1
Reputation: 1
I had the same issue.
What helps is usage of driver.quit();
instead of driver.close();
Upvotes: 0
Reputation: 193348
I don't see any significant error in your code as such. But you need to follow certain guidelines as follows:
While declaring String Firefoxdriverpath
either you need to use single front slashes i.e "/"
e.g. String Firefoxdriverpath="C:/Utility/BrowserDrivers/geckodriver.exe";
OR you need to escape the back slashes i.e "\\"
e.g. String Firefoxdriverpath="C:\\Utility\\BrowserDrivers\\geckodriver.exe";
Let me know if this works for you.
Upvotes: 0
Reputation: 480
Can you please try the below code,
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();
Please let me know if this is working.
Upvotes: 1
Reputation: 1
About the "Javascript error (AddonManager)"... I almost went nuts today trying to fix this, since all the components were installed gradually within the last week.In the end I solved it. Here's the solution and the explanation: geckodriver v.0.16.0 "is only compatible with Selenium 3.4 and greater" (as it says on their page). A week ago selenium 3.3.1 was the last version. As of April 21, selenium3.4.0 was released. I had to recreate the project from scratch, re-adding the Selenium jars. For some reason simply replacing them on the old project, didn't do the trick.
Upvotes: 0
Reputation: 177
What is your Firefox version??
sometimes the problem is the incompatibility between the installed FireFox version and the geckodriver version
Upvotes: 0
Reputation: 11
Please, try it again using "driver.quit" instead of "driver.close".
About the "Javascript error (AddonManager)" I'm still trying to figure out how to fix it too, if someone know a way please share with us :)
Upvotes: 1