Driver path incorrect? What Am I doing wrong [duplicate] - java

This question already has answers here:
Mac OSX - IllegalStateException: The driver is not executable:
(12 answers)
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
(4 answers)
Closed 2 years ago.
I'm trying to use selenium with java to test a login form and I get this error any ideas?
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 com.selenium.Main.main(Main.java:11)
This is my code:
package com.selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) throws InterruptedException {
//Cambia la ruta del teu directori perque funcioni//
System.setProperty("webdriver.gecko.driver","C:\\Users\\Sethei\\Desktop\\M05_Selenium\\geckodriver.exe");
//Test login
WebDriver driver = new ChromeDriver();
driver.get("http://127.0.0.1:8000/login");
driver.manage().window().maximize();
driver.findElement(By.id("email")).sendKeys("email#gmail.com");
driver.findElement(By.id("password")).sendKeys("12345678");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.id("login")).click();
Thread.sleep(3000);

Related

Selenium First Java Script [duplicate]

This question already has answers here:
ChromeDriver and WebDriver for Selenium through TestNG results in 4 errors
(2 answers)
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 2 years ago.
I'm new to selenium and I tried to code my first java script using selenium.
It is giving errors as follows:
**- WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
Watchpoint:FirstSelleniumScript [access and modification] - driver**
I have added selenium to the libaries- selenium-java-3.141.59
java version "1.8.0_251"
I can't understand how to fix it.
Import Necessary Files
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Download The Compatible
ChromeDriver
Now in function you have set the path for chromedriver in your method
String chromePath = "C:/Common_Resourses/";
System.setProperty("webdriver.chrome.driver", chromePath + "chromedriver.exe");
WebDriver driver = new ChromeDriver();
You can also Read more About browser capabilities, it will help you with browser handling
You need to set property first and import chrome driver.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path of the exe file\\chromedriver.exe");
// Initialize browser
WebDriver driver=new ChromeDriver();
Also refer this video https://youtu.be/c86GdHQaLsY

A beginner : How to identify errors in selenium webdriver [duplicate]

This question already has answers here:
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 3 years ago.
Question is:
1) In my simple program how do I identify errors in each line before run it?
2) I placed my program here, while running I am getting many errors. How can I resolve them?
Program:
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Myclass {
public static void main(String[] args) {
System.out.println("Chrome is selected");
System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\Chrome65.0.3325.146\\googlechromeportable.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
//XPath for Email Field
driver.findElement(By.xpath("//*[#id='login']")).sendKeys("xxx#gmail.com");
//XPath for Password Field
//driver.findElement(By.xpath("//*[#id='pass']")).sendKeys("xxxxxxx");
driver.findElement(By.xpath("//*[#id=\"u_0_a\"]")).click();
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
By cannot be resolved`enter code here`
By cannot be resolved
at newpackage.Myclass.main(Myclass.java:16)
You need to specify the driver location , by mistake you gave the browser.exe path so kindly modify your code as below . My chromedriverexe in Jar_files folder and you may need to download it and place it there . I advise you to refer a blog or a video prior to scripting so that you can get more clear idea.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ExecutionbasedOnTReachabilityOfSite {
WebDriver driver;
#BeforeClass()
public void setUp() throws IOException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\Jar_files\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// To start Chrome in Maximized browser window
options.addArguments("start-maximized");
// To remove Chrome is being controlled by automated test software
options.addArguments("disable-infobars");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
It is because you have not added selenium-server-standalone-3.141.59.jar as dependency in build path.
Download JAR from below path:
https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
Right click on Project Folder > Build Path > Configure Build Path > Select & Add downloaded external JAR
All compile time errors that you are getting will be resolved.

Exception in thread "main" java.lang.IllegalStateException:The path to the driver executable must be set by the : system property

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.<init>(ChromeDriver.java:116)
at practise_locators.DatePicker.main(DatePicker.java:11)
Here is my code:
package practise_locators;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DatePicker {
public static void main(String[] args){
WebDriver driver = new ChromeDriver();
System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
driver.get("https://www.google.com");
}
}
The error says it all :
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)
The following phrases from the error implies that there is an error in the line containing webdriver.chrome.driver
The error can be either of the following :
Error in the System Class Method setProperty()(including sequence) :
System.setProperty()
This line should be the very first line in your script.
Error in the specified Key :
"WebDriver.Chrome.driver"
Error in the Value field :
"E:\\chromedriver.exe"
You have to pass the absolute path of the WebDriver through either of the following options :
Escaping the back slash (\\) e.g. "C:\\path\\to\\chromedriver.exe"
Single forward slash (/) e.g. "C:/path/to/chromedriver.exe"
Your code seems to be having two issues as follows :
First issue is in specifying the Key which instead of "WebDriver.Chrome.driver" should have been "webdriver.chrome.driver" as follows :
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
Second issue is in the sequence of mentioning the Key "webDriver.chrome.driver" in your program which should be before WebDriver driver = new ChromeDriver(); as follows :
System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
I have seen many people are using wrong sequence.
the sequence should be.
First set the property and then launch the browser
System.setProperty("webdriver.chrome.driver", "F:/chrome/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://www.google.com");
Download the chromedriver version corresponding to the chrome version in your system from https://chromedriver.chromium.org/downloads . Unzip the file and run the below code in the IDE.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selintroduction {
public static void main(String[] args) {
//Invoking browser
System.setProperty("webdriver.chrome.driver","C:\\Users\\HP\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
}
}
(Path would depend on your file location in the PC.)
I was facing the same error when my code was like so:
System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32.exe");
It works after adding "chromedriver" before ".exe" like so:
System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32\\chromedriver.exe");

java.lang.NoClassDefFoundError: com/google/common/base/Function

I am a beginner in Selenium web driver. I am getting some issues while calling driver.I am attaching the program and error for your reference.
1) I have already tried with standalone jar and individual jar files
2) Path also set correctly in environment variables.
I am using JDK 1.8 and eclipse neon for writing the code.
Please help me if you can..Tried so many ways which is mentioned on internet.Still couldn't identify what is the exact issue. This error started to throw on a particular day when I created a Testng sample program.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Sample22 {
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver",//E://share//geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
//WebDriver driver1 = new MarionetteDriver(capabilities);
WebDriver driver1 = new FirefoxDriver();
}
}
Error is
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at Sample22.main(Sample22.java:12) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
You need to take care of lot of things in your code as follows:
When your code is in Java, System.setProperty line expects the value field to contain either single forward slashes / or escaped backward slashes \\.
The value parameter needs to to be passed as a String within double quotes "..."
If you are using DesiredCapabilities Class, remember to pass the instance of the DesiredCapabilities Class as an argument when you initiate the WebDriver instance.
If you are using import org.openqa.selenium.remote.*; ensure that you have added the latest selenium-server-standalone.jar as an External Jar.
Once you initiate a browser session navigate to some url to confirm if a successful session is established.
Your final code block will look like:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Sample22
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "E:\\share\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.navigate().to("https://google.com");
}
}

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property

package com.merchantPlatform;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MerchantPlatformTest {
public static void main(String[] args) {
System.getProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
// Initialize WebDriver
WebDriver driver = new FirefoxDriver(capabilities);
/* This works fine for versions lesser than Selenium 3. For Selenium 3 and higher, it will throw java.lang.IllegalStateException */
// Maximize Window
driver.manage().window().maximize();
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Navigate to MerchantPlatform URL
driver.get("http://localhost:52939/");
}
}
Error
I am getting the below exception with System.getProperty
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.(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137)
at com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)
You have to use System.setProperty not the System.getProperty as follows.
System.setProperty("webdriver.gecko.driver",
"C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
I have noticed that you are using wrong syntax, to opening the browser.
Instead of using System.getProperty, You have to use System.setProperty as mentioned below.
System.setProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
For more details on this issue, refer this page.

Categories

Resources