This question already has answers here:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
(4 answers)
Closed 4 years ago.
I was written this code to open Mozilla Firefox browser
package com.webdrivercommands;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WDcommands_Test1 {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
//Launch chrome Browser
//setproperty(method)
System.setProperty("Webdriver.gecko.driver", "C:\\Java Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
//WebDriver(class)
//driver (object)
//wait Time
Thread.sleep(5000);
//close the browser close(method)
driver.close();
}
}
After Run the program i got the below error..but already extract the geckodriver(Firefox driver) into my system
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:847)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:125)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:43)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:168)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:346)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:168)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103)
at
com.webdrivercommands.WDcommands_Test1.main(WDcommands_Test1.java:17)
example 1: launch FF in blank temp profile:
#BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();}
example 2: launch FF in blank temp profile with some preferences
#BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile selenium_profile = new FirefoxProfile();
selenium_profile.setPreference("browser.download.folderList",2);
selenium_profile.setPreference("browser.download.dir", "C:\\Users\\pburgr\\Desktop\\BP_usr_tmp\\");
selenium_profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
options.setProfile(selenium_profile);
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();}
example 3: lauch FF with existing FF profile:
#BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();}
Related
I have written a selenium script,while creating project it is asking for create module if i don't create this module, directly create project run the script means will get this error."Error occurred during initialization of boot layer
java.lang.module.FindException: Module format not recognized: E:\selenuim\chromedriver_win32\chromedriver.exe
//This is my script//
public class LoginDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","E:\\chromedriver.exe");
WebDriver driver =new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Login to an application
driver.get("http://aesportal.azurewebsites.net/");
driver.findElement(By.name("email")).sendKeys("demo");
driver.findElement(By.name("password")).sendKeys("demo");
driver.findElement(By.xpath("//Button[#type='submit'")).click();
}
}
I am trying to run a test on Remote Machine for selenium Grid and it gives me expection erro
Expection
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
Here is my code
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
String nodeURL;
String baseURL;
System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.19.1-win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.BINARY,new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe").getAbsolutePath());
WebDriver driver = new RemoteWebDriver(new URL("http://10.132.48.16:5566/wd/hub"),capabilities );
driver.get("http://google.com");
System.out.println(driver.getTitle());
I little help here will be appreciated.I am simply trying to open a site using selenium and here is the code. Getting java.lang.IllegalStateException error.
package pkg1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class training1 {
/**
* #param args
*/
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}
}
----- 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:738)
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:330)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
at pkg1.training1.main(training1.java:14)
You must set path of the chromedriver.exe before calling new ChromeDriver()
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}
I am a begineer in selenium and trying my own after installation of eclipse, java, selenium, TestNg and started writing the below code.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
at Mypackage.MyClass.main(MyClass.java:8)
package Mypackage;
public class MyClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://google.com";
String expectedTitle = "Welcome: Hello";
String actualTitle = "";
driver.get(baseUrl);
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)) {
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
}
}
you need to add selenium webdriver jar files to the project
right click on project-->goto build path-->configure build path-->click on "Add external jars"-->add selenium jar files from your local machine-->click ok-->now mouseover on WebDriver in your code-->click "import webdriver"--now run your code-->you will get rid of the exception.
I was trying to launch safari browser on real device(iPhone 4) using appium. but it is giving following error.
Unable to install [/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app] to device with id [fdaxxx76].
Error [Error: Command failed: /bin/sh -c /Applications/Appium.app/Contents/Resources/node_modules/appium/build/fruitstrap/fruitstrap install --id fda51be7184f865f02de4f4c6cb8fff760964e76 --bundle "/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app"
Below is my sample code:
DesiredCapabilities cap = new DesiredCapabilities();
private static WebDriver driver;
#BeforeTest
public void prep() throws MalformedURLException {
System.out.println("Script started");
cap.setCapability("platformName", "iOS");
cap.setCapability("platformVersion", "8.3");
cap.setCapability("deviceName", "iPhone4");
cap.setCapability("udid", "fda51be7184f865f02de4f4c6cb8fff760964e76");
cap.setCapability("browserName", "Safari");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
#Test
public void googleTest() {
System.out.println("main method");
driver.get("http://google.com");
}
You need to create a provisioning profile to deploy it to a real device.
Follow instructions here.
Hope this helps,
Liam