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")
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 have added all the files in classpath of library. I am able to see org.openqa.selenium.chrome/ChromeDriver class and org.openqa.selenium/WebDriver class. Still Eclipse is not able to locate the class files. Below is my code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver=new ChromeDriver();
}
}
Kindly help to resolve. Thanks.
Well, I think this is not a simple "import" problem. First you need to set the path for your chrome driver using System.setProperty, just like the example below:
#Before
public void BeforeTest() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/driver/chromedriver"); //On windows ...chromedriver.exe
driver = new ChromeDriver();
driver.get("https://www.amazon.com.br");
}
If you are really having an import problem, maybe something is missing on the classpath. If this is the case I recommend you to use Maven and download the dependencies.
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();
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,