Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\geckodriver.exe - selenium

I am getting below exception while trying to open a site
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist: C:\Selenium\geckodriver.exe at
com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at com.tst.Test.main(Test.java:12)
My code is:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:/Selenium/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");
I am using selenium 3 with geckodriver-v0.19.1-win64.zip. and java version is 1.8.
Please help me out

You need to setPath properly for binary file. On windows, I prefer \\ instead od /, Can you please try this?-
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");

Related

Selenium not opening the browser and the code instead runs in JAVA console and throws error message

package firstSeleniumTesting;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class testingAutomation {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.drive", "C:\\SeleniumDriver\\chromedriver_win32");
WebDriver driver = new ChromeDriver(); //Launches Firefox
driver.close();
}
}
I get the following error
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable 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 https://chromedriver.storage.googleapis.com/index.html
at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:280)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:132)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:38)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:231)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:434)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:127)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:46)
at firstSeleniumTesting.testingAutomation.main(testingAutomation.java:13)
Add the .exe in the chromedriver
Use like this
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDriver\\chromedriver_win32.exe");
WebDriver driver = new ChromeDriver();
driver.close();

Exception in thread Unresolved compilation problems:

This is my script:
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.close();
}
}
When I run the script, am getting below error, I tried to add the java lib in Class path instead of Module path, still the issue not resolved, someone please help;
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type FirefoxDriver cannot be resolved to a type at sampleTests.AdminLogin.main(AdminLogin.java:10)
You have to set the path of the Geckodriver (the executable that is used for Firefox tests using Selenium).
Search for Geckodriver in Google.
Download the executable as per your system (Win/Mac/Linux)
Set the path of the executable in your tests as given below -
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver",Path_of_Firefox_Driver");
// example for Windows
System.setProperty("webdriver.gecko.driver",D:\\GeckoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://testautomationu.applitools.com/");
driver.quit();
}
}

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Sujata_Selenium_workspace\chromedriver.exe [duplicate]

This question already has an answer here:
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe with ChromeDriver
(1 answer)
Closed 3 years ago.
xception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Sujata_Selenium_workspace\chromedriver.exe
Errors is showing.
package seleniumWebdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Sujata_Selenium_workspace\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.seleniumhq.org/download/");
}
}
I think your chromedriver does not placed in the path your defined "C:\Sujata_Selenium_workspace\chromedriver.exe"
Either place the chromedriver in the path or place it somewhere in D or E drive like
D:/Selenium/chromedriver.exe
Code like
System.setProperty("webdriver.chrome.driver", "D:/Selenium/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.seleniumhq.org/download/");

selenium webdriver using firefox for google search/selenium testing

I am trying to open google.com first then type "selenium testing".
I only wanted to use className for webdriver using eclipse but I am getting the following error.
Exception in thread "main"
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"class name","selector":"Tg7LZd"}
Command duration or timeout: 37 milliseconds
Here is my code:
package coreJava;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Training1 {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.findElement(By.className("gLFyf")).sendKeys("selenium testing");
driver.findElement(By.className("Tg7LZd")).click();
}
}
How do I fix this?
This error message...
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"Tg7LZd"}
...implies that the GeckoDriver was unable to find any element as per the Locator Strategy you have used.
Your main issue is the classNames you have used are based on JavaScript and are generated dynamically which we can't guess before they are generated.
As an alternative you can use the following solution:
package coreJava;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Training1 {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement myElement = driver.findElement(By.name("q"));
myElement.sendKeys("selenium testing");
myElement.submit();
}
}
System.setProperty("webdriver.gecko.driver", "geckodriver");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://google.com");
Thread.sleep(3);
driver.findElement(By.className("gsfi")).sendKeys("selenium testing");
Thread.sleep(3);
driver.findElement(By.className("sbqs_c")).click();
Thread.sleep(3);
driver.close();
This is working code
.
These will open the google chrome and then write "selenium testing" in search box and then search it using the class.

Error are coming when trying to open chrome using selenium first time

Exception thread "main" org.opens.selenium.WebDriverException:unknown error :chrome failed to start
I guess you are not adding Chromedriver path in code, first download the Chromedriver and add it like this
public class Test1
{
public static void main(string[] args)
{
System.setProperty("webdriver.chrome.driver","E://batc‌​h235//‌​chromedriver‌.exe");
C‌​hromeDrive‌​r driver=new ChromeDriver();
driver.get("https://www.google.co.in");
}
}
Add your chromedriver path in place of E:/software and tools/chromedriver_win32/chromedriver.exe