Not able to launch Chrome browser using Selenium Webdriver - selenium-webdriver

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

Write "webdriver.chrome.driver" instead of "webdriver.chrome.Driver"
Just lowercase instead of uppercase.

When you are setting the properties, you can't use uppercase
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver.exe");
WebDriver driver = new ChromeDriver();
user.dir will take you to the current working directory.
Let me know if it works for you.

Related

selenium browser launch by octopus [duplicate]

The release notes for ChromeDriver 2.33 says that ""Fixes a bug which caused Resizing/Positioning Window commands to fail on Chrome 62+" however this still seems to be an issue when i am using Chrome 62+ browser. Maximizing chrome window using chrome driver results in below exception. Does anyone know a solution please?
Another thing i noticed is, though i installed latest chromedriver (v2.33) from https://chromedriver.storage.googleapis.com/index.html?path=2.33/, the log printed below says Driver info: chromedriver=2.25.426923 !!
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: cannot get automation extension from unknown error:
page could not be found:
chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=62.0.3202.62) (Driver info:
chromedriver=2.25.426923
(0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT
10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
There are exactly 2 issues.
As you mentioned, you have installed latest chromedriver (v2.33) but the log printed below says Driver info: chromedriver=2.25.426923, this issue must be addressed first. You can consider to manually kill all the dangling chromedriver.exe tasks from the Task Manager. Additionally you can consider to use CCleaner to wipe out all the rotten OS stuffs from your system. Take a system reboot if required. Finally ensure that what ever the absolute location of chromedriver.exe you are using within System.setProperty() ensure that the chromedriver binary is of version 2.33.
Finally, it is suggested to use ChromeOptions class to maximize the Web Browser as follows:
System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");
Here are some of the alternatives which may solve your question:
Using maximize() from WebDriver.Window interface :
driver.manage().window().maximize();
Using setSize(Dimension targetSize) from WebDriver.Window interface:
driver.manage().window().setSize(new Dimension(800, 600));
Using addArguments("--start-maximized") through ChromeOptions:
chromeOptions.addArguments("--start-maximized");
Using addArguments("--window-size=1920,1080") through ChromeOptions:
chromeOptions.addArguments("--window-size=1920,1080");
Using executeScript() from JavaScriptExecutor interface:
((JavaScriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");
You can find a related discussion in Chrome - org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension at driver.manage().window().maximize();.
I believe there were some old chrome driver processes running in backend and same were being picked up when it was invoked via code. I deleted all processes instances, deleted old version of chrome driver, added the new 2.33 version and it worked. Thanks all for your suggestions.
I think the reason behind it may be your chrome version. Try again with updating your chrome browser. I have faced this type of issues for compatibility between chrome browser & the driver
Use class ChromeOptions.
System.setProperty("webdriver.chrome.driver", "h:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get(url);

Unable to launch Firefox browser from Selenium Webdriver version 3.4.0

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
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 :)
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.
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)
What is your Firefox version??
sometimes the problem is the incompatibility between the installed FireFox version and the geckodriver version
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.
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.
I had the same issue.
What helps is usage of driver.quit(); instead of driver.close();
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.

Selenium 3.0.1 webdriver error for Firefox in Eclipse

I am using Ubuntu 14 and installed Eclipse with compiler compliance level 1.7 using selenium 3.0. If I decrease the level to 1.4, it shows me error on sendkey() function. I set the property:
System.setProperty("webdriver.gecko.driver","/home/Rrrrr/Downloads/jars/geckodriver");
I use following code:
WebDriver driver;
driver = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver","/home/Rrrrr/Downloads/jars/geckodriver");
driver.get("http://www.google.com");
but it still gives me following error. Is it version problem or any other?
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
If by compliance level you mean Java version then you must set it to 8. Have a look at the release notes for v3.0.0-beta1 where it says:
Minimum java version is now 8+
I Got solution over above code
"Sequence of code is wrong"
Sequence must be as follows
WebDriver driver;
System.setProperty("webdriver.gecko.driver","/home/Rrrrr/Downloads/jars/geckodriver");
driver = new FirefoxDriver();

I am getting the following exception while launching face book using chrome browser in Selenium can any one suggest me the solution for this

Exception in thread "main" java.lang.IllegalStateException: The path
to the driver executable must be set by the webdriver.chrome.driver
system property; for more information, see
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html at
com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at
org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at
org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116)
at New.HelloWorld.main(HelloWorld.java:16)
You need to use this code to set the location of chromedriver before initializing the driver. Use the method setProperty(String key, String path):
System.setProperty("webdriver.chrome.driver", "/tpt/chromedriver.exe");

How does IEDriverServer.exe and Chromedriver.exe works?

I have following questions regarding seleniumn webdriver:
How does IEDriverServer.exe and Chromedriver. exe works. i.e. What happens when these exes are executed.
What is the significance of using these exes
These executables are used to run the webdrivers. These need to be specified in the System.setProperty. This is something that needs to be done for IE and Chrome but not for Firefox.
Running the .exe by themselves will probably do nothing.
Example Java Code for ChromeDriver:
System.setProperty("webdriver.chrome.driver","/.../chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(URL);

Resources