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();
Related
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?
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.
i am trying this code but it fails
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Fijan {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:Users\\Devrepublic\\Documents\\fijan\\selenium\\chromedriver_win32\\chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("");
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from ChromeDriver to WebDriver
at prac.Fijan.main(Fijan.java:12)
how to overcome from this problem
The chromedrive path should end with extension of the driver.
So, change your line as below.
System.setProperty("webdriver.chrome.driver", "C:Users\\Devrepublic\\Documents\\fijan\\selenium\\chromedriver_win32\\chromedriver.exe");
I want to setup the selenium with netbeans and got an error.
If any one help me, its good for me.
Code:
package testfirst;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
*
* #author haseeb.saleem
*/
public class Testfirst {
/**
* #param args the command line arguments
*/
private static WebDriver driver = null;
public static void main(String[] args) {
// TODO code application logic here
System.setProperty("WebDriver.chrome.driver", "C:\\Users\\haseeb.saleem\\Desktop\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https:\\google.com.pk");
}
}
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:754)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at testfirst.Testfirst.main(Testfirst.java:24)
C:\Users\haseeb.saleem\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1
BUILD FAILED (total time: 1 second)
As stated in the exception, the name of the system property is: webdriver.chrome.driver and not WebDriver.chrome.driver. Please make changes accordingly.
It is syntax error in setproperty() method, the correct code is :
private static WebDriver driver = null;
public static void main(String[] args) {
// TODO code application logic here
System.setProperty("webdriver.chrome.driver", "C:\\Users\\haseeb.saleem\\Desktop\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https:\\google.com.pk");
}
Also it is good to use single forward slash
System.setProperty("webdriver.chrome.driver", "C:/Users/haseeb.saleem/Desktop/chromedriver.exe")
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();