Selenium - Webdriver executable doesnot exist error - java

I am getting below error while trying to execute my selenium code shown below:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "‪C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
}
}
Error - Exception in thread "main" java.lang.IllegalStateException:
The driver executable does not exist:
C:\Selenium\Introduction\‪C:\chromedriver at
com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141)
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.(ChromeDriver.java:123)
at Demo.main(Demo.java:11)
I have placed the chrome driver in the location mentioned and the version is also double checked.

This is very minor change with static mode, try with :
static WebDriver driver;
static String driverpath = "C:\\chromedriver.exe";
public static void main(String [] args)
{
System.setProperty("webdriver.chrome.driver", driverpath);
driver = new ChromeDriver();
}
As we are executing Java static main method, its requires to handle driver with Static variables.

Related

WebDriver cannot be resolved to a type and ChromeDriver cannot be resolved to a type

Please find the code below,
My chrome driver has latest Version 103.0.5060.13
I have already added jar files in the Project->Properties->Java Build path->Libraries->Module Path
The error is on this line
WebDriver driver=new ChromeDriver();
package Selenium.webdriver.basictest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Secondclass {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\97477\\Downloads\\chromdrivefolder\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://saucedemo.com/");
}
}

how to resolve this problem cannot convert from ChromeDriver to WebDriver

public static void main(String[] args) {
String browserName = "chrome";
WebDriver driver = null;
if (browserName.equalsIgnoreCase("chrome")) {
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase("edgebrowser")) {
driver = new EdgeDriver();
i write exactly but still am getting mismatch error
rename your class
add import org.openqa.selenium.WebDriver
add property webdriver.chrome.driver
Code:
package selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class Gayatri {
public static String chromedriverPath = System.getProperty("user.dir") + "\\resources\\chromedriver.exe";
public static void main(String[] args) {
String browserName = "chrome";
WebDriver driver = null;
if (browserName.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", chromedriverPath);
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase("edgebrowser")) {
driver = new EdgeDriver();
}
driver.get("https://www.stackoverflow.com");
System.out.print(driver.getTitle());
driver.quit();
}
}
Output:
Starting ChromeDriver 100.0.4896.60 (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896#{#875}) on port 19334
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Kvě 02, 2022 8:15:46 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Stack Overflow - Where Developers Learn, Share, & Build Careers

Webdriver cannot be resolved to a type error

Below are the versions i used.
Java 11.0
Selenium webdriver 3.14
Can anyone please let me know the solution for this.
package packageone;
import org.openqa.selenium.WebDriver;
public class Firstclass {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver= new chromedriver();
}
}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Firstclass {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver= new ChromeDriver();
}
}
Differences:
Line 2 - added import for ChromeDriver (your IDE should suggest you)
Line 7 - added path to crhrome driver; Don't forget to replace "/path/to/chromedriver" with a real FULL path to executable of crhomeDriver
Line 8 - new chromeDriver() ---> new ChromeDriver();
Ready examples of starting chromeDriver

Trying to launch firefox browser using selenium jar files in eclipse getting e

I'm trying to launch firefox browser from eclipse using selenium as I'm learning selenium.
My tutor wrote the below code but when i'M trying the same code I get this exception-
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
Link1. The latest version can be downloaded from
Link2
Code:
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
You are facing this exception, because you have not used gecko driver , which is required for launching and sending command in selenium.
You can download the latest version of gecko version from here
Try this :
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
static WebDriver driver ;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
While you work with Selenium ver3.x, GeckoDriver ver0.21.0 and Firefox ver61.0.1, you need to download the latest GeckoDriver from mozilla/geckodriver and store it anywhere within your system. In your code you need to provide the absolute path of the GeckoDriver through the System.setProperty() line as follows:
package demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A_Firefox
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Note: Replace the packagename (demo in this example) with your own package name.

I see an error while running a package in Eclipse

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
This is my code.
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MyClass {
public static void main(String[] args) {
//declaration and instatiation of objects/variables
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle ="";
//launch firefox and direct it to the URL
driver.get(baseUrl);
//get the actual value of the title
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed");
}else {
System.out.println("Test failed");
}
//close firefox
driver.close();
//exit the program
System.exit(0);
}
}
For selenium 3.0 and above it is mandatory to specify gecko.driver path. Add below lines to your code before initializing driver and error will not appear.
System.setProperty("webdriver.firefox.marionette","xxx\geckodriver.exe");
//xxx - path to geckodriver.exe file
WebDriver driver = new FirefoxDriver();

Categories

Resources