The driver executable must exist - java

import org.openqa.selenium.WebDriver;
import org.openqa selenium.chrome.ChromeDriver;
public class SeliniumTest {
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver", chromedriver.exe");
WebDriver driver = new Chrome driver();
driver.get("https://www.google.com");
enter code here
}
}
When I run this, I get an illegal Exception:
the driver executable must exist: c:\TestProject\drivers\chromedriver.exe
I tried multiple times to install the IDE and download the right version of drivers on both Mac and Windows, but I get the same error. Can someone please help?

Related

updated correct chrome driver path/driver version and add selenium jar too, but still getting below issue , could you help me for this?

code :
package Demo1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Chrome {
public static void main(String[] args) {
WebDriver driver= new ChromeDriver();
System.setProperty("webdriver.chrome.driver","C:\\New folder\\chromedriver.exe");
driver.get("https://www.youtube.com/watch?v=BtmeQOcdIKI");
System.out.println(driver.getTitle());
}
}
error :
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:847)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at Demo1.Chrome.main(Chrome.java:9)
You are setting the system property too late.
Looking at the stacktrace, the exception is being thrown while executing the following line of your code:
WebDriver driver= new ChromeDriver();
At that point, the line of your code that sets the system property hasn't been reached yet.
Evidently, you need to set the system property before creating the ChromeDriver object.
The first line in your main method should be :
System.setProperty("webdriver.chrome.driver","C:\\New folder\\chromedriver.exe");
something like this.
public class Chrome {
WebDriver driver = null;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\New folder\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.youtube.com/watch?v=BtmeQOcdIKI");
System.out.println(driver.getTitle());
}
}
should get the job done.

org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:42)

I am trying to run a simple code in eclipse but it is not working.
Details:
Firefox version - 61.0b4 (64-bit), Jdk - jdk1.8.0_121, Eclipse oxygen
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestBrowsers {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
}
}
Error description:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:42)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:136)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:165)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at TestBrowsers.main(TestBrowsers.java:8)
May not fix the issue but there is a potential misspelling, highlighted in ().
Firefox(b)Driver driver = new FirefoxDriver();

Open Chrome with selenium

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:/Users/myPC/Desktop/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
So I downloaded chromedriver.exe and tried opening Chrome using the following code, but every time I run this code I get the following error:
Error:java: package com.google.common.collect does not exist
And also whenever I try and run chromedriver.exe from desktop, chrome does not want to open.
Thanks in advance
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:/Users/myPC/Desktop/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("http://www.google.com");
}

java Eclipse selenium webdriver throws exception

So I was just writing a simple test program to open google in firefox. And it's not working.
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:111)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:312)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:122)
at Test.main(Test.java:7)
My code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String args[]) {
WebDriver driver = new FirefoxDriver();
System.out.println("Hello Google...");
driver.get("http://google.com");
}
}
Please download Geckodriver from below mentioned link
https://github.com/mozilla/geckodriver/releases.
In Your Test program set Geckodriver path-
public class links {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
//System.setProperty("webdriver.firefox.marionette", "D:\\vidya\\selenium\\geckodriver-v0.13.0-win64\\geckodriver.exe");
driver =new FirefoxDriver();
driver.manage().window().maximize();

Error "BeanShell 2.0b4 - by Pat Niemeyer (pat#pat.net) bsh%" while running code via eclipse

on running the below selenium code, i am getting an error in a popup:
Eclipse version:3.4.2, Selenium stand alone server used:2.51.0
I had the selenium server added to my project. Not sure why this error is popping up
package upointPckg;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Upoint {
public static void main(String[] args){
String url = "www.google.com";
WebDriver Driver = new FirefoxDriver();
Driver.manage().window().maximize();
Driver.get(url);
}
}
Also tried running it without importing the drivers, it shows the same error:
package uPointPackage;
public class UPointClass {
public static void main(String[] args) {
String url = "www.google.com";
System.out.println(url);
}
}
BeanShell 2.0b4 - by Pat Niemeyer (pat#pat.net)
Hi Guys, I was also getting same error because i had mentioned main() method within multiple classes under same package. So while executing current class from run icon at header in eclipse, compiler was getting confused to which main() method need to be executed.
So solution is to write main() method only in single class within a package or execute only single class by right click on that particular class and run as Java Application,

Categories