selenium not get http - java

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

Related

Selenium issue,Help me on that [duplicate]

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();
}

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();
}

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();

TestNG error null point exception error

Hi I am receiving following error can someone help me out with debugging below code,
package testngpackg;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ARXNewTest {
ChromeDriver driver;
#BeforeMethod
public void set() {
//ProfilesIni profile = new ProfilesIni();
//FirefoxProfile testprofile = profile.getProfile("default");
// testprofile.setAcceptUntrustedCertificates(true);
//testprofile.setAssumeUntrustedCertificateIssuer(true);
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Web Driver 3.0.1\\geckodriver-v0.12.0-win32\\geckodriver.exe");
WebDriver driver = new ChromeDriver();
String baseURL = "<URL>";
driver.get(baseURL);
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
}
#Test
public void OpenBrowser() {
driver.findElement(By.linkText("Log In")).click();
driver.switchTo().frame(0);
driver.findElement(By.id("tx_username")).sendKeys("my email id");
}
}
Error
FAILED: OpenBrowser
java.lang.NullPointerException
at testngpackg.ARXNewTest.OpenBrowser(ARXNewTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
I am getting null point error while execution of above code
You find a NullPointerException cause driver is not getting initialized before that point. You tried to initialize a WebDriver instance inside beforeMethod() method, but it was local.
Use following code :
driver = new ChromeDriver();
Instead
WebDriver driver = new ChromeDriver();
Hope it will help you.
Here is the solution to your Question-
A few words about the Solution:
Avoid creating unnecessary instances. You have ChromeDriver driver; but not used it anywhere.
Keep your methods & code-blocks separated so that you can identify them properly.
Remove the unwanted code when you are asking for help //ProfilesIni profile = new ProfilesIni();
In System.setProperty you have mentioned the Key as webdriver.chrome.driver but you have provided the value as C:\\Selenium Web Driver 3.0.1\\geckodriver-v0.12.0-win32\\geckodriver.exe
Keep you code properly formatted so that it is easier to understand code-blocks.
Manage the opening & closing of { & } so you don't run into unexpected results.
Provide names to the methods as per the functiosn achieved through the code within. Your OpenBrowser() method have nothing to do with Browser opening.
Here is the working set of your own code with some minimal tweaks:
public class Q43910679_null_pointer
{
#BeforeMethod
public void set()
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseURL = "https://gmail.com";
driver.get(baseURL);
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
}
#Test
public void OpenBrowser()
{
System.out.println("Open Browser Method");
}
}
Let me know if this Answers your Question.

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