Selenium issue,Help me on that [duplicate] - java

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.
Prog
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class login {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\Users\\Vishal\\Downloads\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.facebook.com");
}
}
Error
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.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at login.main(login.java:8)

If you are using the latest version of Gecko and a recent version of Firefox, your answer might be here.
To resume, try something like this (if the path to GeckoDriver is correct) :
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "yourGeckoPath");
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.facebook.com");
Thread.sleep(5000);
driver.quit();
}

Related

How to resolve IllegalState Exception in Java-Selenium (chrome browser version->101.0.4951.67 & chromeDriver version->101.9.4951.41)

package Selenium_Java;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GmailTest
{
public static void main(String[] args) throws Throwable
{
System.setProperty("WebDriver.chrome.driver", "F:\\Software Repo\\KRN infoTech_Selenium\\Prerequisites\\chromedriver_win32\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://mail.google.com/mail/&ogbl");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
driver.close();
}
}
I am unable to launch URL using ChromeDriver. I am getting below error message -
The path to the driver executable The path to the driver executable must be set by the webdriver.chrome.driver system property;

I can't open anything with Selenium WebBrowser Java

I am trying to open local files with Selenium. With the code below, Firefox is opening, but I have the error org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..
File gecko = new File("resources/geckodriver64.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("file:///C:/example/myfile.pdf");
Can someone help me ? I couldn't find anything on the internet.
We have now come to the part where you will see how you can use GeckoDriver to launch Firefox. You will first need to download GeckoDriver and then set its path. There are three different ways to use GeckoDriver with Selenium 3:
With setting system properties in the test
With setting system properties by Environment Variable
With setting up Browser Desired Capabilities
Download Gecko Driver:-
1- Gecko Driver different versions can be downloaded from Github. I suggest you to use the latest version.
Set System Properties for Gecko Driver:-
Code to set the System properties is System.setProperty(“webdriver.gecko.driver”,”Path to geckodriver.exe”);
The complete program to launch the GeckoDriver will be like this:
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "D:\\\\XXXX\\trunk\\Library\\drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.toolsqa.com");
Thread.sleep(5000);
driver.quit();
}
}
Check Below answer. This is working solution on my machine. Please check your firefox version too.
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class geckodriver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
Thread.sleep(5000);
// DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// capabilities.setCapability("marionette", true);
//
// WebDriver driver = new FirefoxDriver(capabilities);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FireFoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}}
Can you try below code ?
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}

selenium not get http

I tried below code in eclipse. When I run this code firefox will open but driver.get("https://www.easybooking.lk/login"); not working. Please help me in resolving this error
package login;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class easylogin {
//public static void main(String[] args) {
// TODO Auto-generated method stub
public static void main(String[] args) throws InterruptedException {
//Object webdriver;
System.setProperty("webdriver.gecko.driver", "D:\\jjpppp\\geckodriver-v0.17.0-win64/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("https://www.easybooking.lk/login");
I am getting below error. How can I fix this? I added selenium firefox drivers
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:872)
at login.easylogin.main(easylogin.java:20)
As per error message, it seems there is some problem in implicitlyWait. It does not seems to be working. Just comment this code and check once
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
Have you tried to change the path to your driver
in the following way:
D:\\jjpppp\\geckodriver-v0.17.0-win64\\geckodriver.exe
You might also have a look at the following change in order to be sure that your DOM is completely loaded:
WebDriverWait logWait = new WebDriverWait(driver, 10);
logWait.until(ExpectedConditions.presenceOfElementLocated(by));
driver.findElement(...)
The issue is because your browser and geckodriver are not compatible.
I tried with latest firefox version(56.0) and geckodriver 18. It worked fine.
Then I tried firefox(56.0) and geckodriver 17. It gave me similar issue.
So better use latest firefox and geckodriver.
try putting implicit wait after navigating to web address.
public static void main(String[] args) {
// TODO Auto-generated method stub
public static void main(String[] args) throws InterruptedException {
//Object webdriver;
System.setProperty("webdriver.gecko.driver", "D:\\jjpppp\\geckodriver-v0.17.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.easybooking.lk/login");
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
this will help you to wait till web-page loads next find element.
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
remove this and try

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

Following previous related issues posted and given resolution, I tired everything but still getting same error for FireFox, Chrome & Internet Explorer.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Search {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
System.getProperty("webdriver.gecko.driver",
"C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-
win64\\geckodriver.exe");
driver.get("http://www.wikipedia.org");
WebElement link;
link = driver.findElement(By.linkText("English"));
link.click();
Thread.sleep(5000);
WebElement searchbox;
searchbox = driver.findElement(By.id("searchInput"));
searchbox.sendKeys("Software");
searchbox.submit();
Thread.sleep(5000);
driver.quit();
Shouldn't that be System.setProperty() instead of .getProperty()?
System.setProperty("webdriver.gecko.driver, "C:\\Users\\...\\geckodriver.exe");
Use that gecko driver system property before driver intialization
So first line gecko property and next line driver=new so and so..
Use .setProperty and declare it after providing the path to webdriver
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();

ChromeDriver cannot navigate to URL in eclipse

I am very new to Cucumber and get the following error using ChromeDriver to request a URL:
java.lang.IllegalStateException: The path to the driver executable
must be set by the webdriver.chrome.driver system property; for more
information, see http://code.google.com/p/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:177)
My code:
package cucumber.features;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class AddToList {
WebDriver driver = null;
#Given("^I am on Todo site$")
public void onSite() throws Throwable {
driver = new ChromeDriver();
driver.navigate().to("http://localhost");
System.out.println("on todo site");
}
#When("^Enter a task in todo textbox$")
public void enterTask() throws Throwable {
driver = new ChromeDriver();
driver.findElement(By.name("task")).sendKeys("Test Unit Using Cucumber");
;
System.out.println("task entered");
}
#Then("^I click on add to todo$")
public void clickAddToTodo() throws Throwable {
driver = new ChromeDriver();
driver.findElement(By.xpath("//input[#value='Add to Todo' and #type='button']"));
System.out.println("add button clicked");
}
}
I had a similar problem when using selenium library. I found this line before creating my driver fixed it.
System.setProperty("webdriver.chrome.driver", PATH_TO_CHROME_DRIVER);
Here is simple project that could help you.
this.driver.get(URL);
Also, I don't think your When and Then should create new ChromeDrivers. Only the Given. I use the setUp method to instantiate it
#Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "..//..//files//drivers//chromedriver.exe");
this.driver = new ChromeDriver();
}

Categories