I am using Mozilla 51.0.1 and Eclipse Lunar 3.0.1. When I am trying to run my code I am not able to get URL in the browser, it just opens.
package SessionPack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SessionCalss {
public static void main(String arg[])
{
System.out.println("String");
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "C:\\New folder\\geckodriver.exe");
driver=new FirefoxDriver();
driver.get("www.gooogle.com");
}
}
Your request is wrong in two places:
You write extra character "o" - gooogle
You have to added https:// before URL-adress - https://www.google.com
After fix this code will be work.
You have to specify http:// or https:// specifically; you have to change your URL string from:
www.gooogle.com to https://www.gooogle.com
Related
this is my class*****
```
package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.findElement(By.id("userName")).sendKeys("https://sdzclient-kpiregister.azurewebsites.net/");
driver.findElement(By.id("passwords")).sendKeys("Gravity#123");
driver.findElement(By.id("btn-sdz-login")).click();
}
}
```
on Hover the SendKeys method will get an error like"The method sendKeys(char sequence[] )in the type webelement is not applicable for the string".***
When you are working with Selenium you need to follow a few steps
//first you add your chrome driver path
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
// second you need to initialize the WebDriver object - and you did it
WebDriver driver=new ChromeDriver();
// third you need to tell to the WebDriver object where to go, what page to load
driver.get("https://sdzclient-kpiregister.azurewebsites.net/");
//below is the login part
driver.findElement(By.id("userName")).sendKeys("SET_YOUR_USERNAME_HERE");
driver.findElement(By.id("passwords")).sendKeys("Gravity#123");
driver.findElement(By.id("btn-sdz-login")).click();
your error was throw because the driver didn't know where to go but you tried to send some keys instead of a driving page path
I am not sure, when you said you are not able to change compilation version. You can change as per below screen grab.
..project>right click>build path>configure build path >java compiler>
Do not forget to click on Apply after changing compilation version.
Executing simple class
Enter code here
package lesson1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Brf {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin#123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful -Passed");
}
else
{
System.out.println("Login Unsuccessful -Failed");
}
driver.close(); //Closes the Browser
}
}
Getting the error:
Error on simple class in selenium webdrive:
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:335)
You are getting this error because you haven't set the path of gecko driver in your code.
Please set the path of gecko driver before creating a new instance of Firefox driver.
System.setProperty("webdriver.gecko.driver"," Path to geckodriver");
WebDriver driver = new FirefoxDriver();
Need to add driver path, if you are using selenium jars above 3.0 , if you are using selenium jars below 3.0 your code is good to go, but i guess you are using selenium jars above 3.0
Public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver"," Path to geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin#123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful -Passed");
}
else
{
System.out.println("Login Unsuccessful -Failed");
}
driver.close(); //Closes the Browser
}
The cause of the error is that you don't have a proper setup for detection of a GeckoDriver file named "geckodriver.exe" (this prevents you from being able to open Firefox with your program). In case you don't have such a file, you can download one h̲e̲r̲e̲ (I suggest getting the latest version).
With such a file, you can carry out one of the following two procedures to rectify your problem:
Method 1
Add the path of the folder containing the "geckodriver.exe" file to your PATH environment variable value (instructions on how to modify this variable value can be seen h̲e̲r̲e̲).
Method 2
Prepend the body of your main method with the following statement (where GECKODRIVER_PATH represents the path of the "geckodriver.exe" file):
System.setProperty("webdriver.gecko.driver", "GECKODRIVER_PATH");
Set the gecko driver path which is initialise the firefox driver.
I started to learn SeleniumWeb driver with Java and I write some code like this :
package firstPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class firstScript {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http//:www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("mysql excel 2013");
element.submit();
}
}
If I run this code, mozilla only start, It is not contiune. I want to it to "google" and search "mysql excell 2013". How can I do?
I am using the selenium-server-standalone-3.5.3.jar in which this code is not working but when I changed jar from 3.5.3 to 2.44.0 then Its working fine.
Its opening the firefox and search the "mysql excel 2013" and got the results of it.
So you need to change the selenium version or need to change the browser from firefox to chrome.
Getting the following error
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist:
/Users/Golcha/Desktop/Automation/geckodriver.exe
Code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class selenium{
private static WebDriver driver;
public static void main(String[]args){
System.setProperty("webdriver.gecko.driver","Users/Golcha/Desktop/Automation/geckodriver.exe");
setDriver(new FirefoxDriver());
}
public static WebDriver getDriver() {
return driver;
}
public static void setDriver(WebDriver driver) {
selenium.driver = driver;
}
}
Try below code but check the path of geckodriver properly before executing the below code or I ll suggest you to paste geckodriver in C drive or any other drives to make your path simple as below one :
System.setProperty("webdriver.firefox.marionette", "C:\\geckodriver.exe");
It should work without any problem . All the best !
I thing you have not mentioned the complete(full) path for the Geckodriver in your System.setProperty() method. you have missed the drive letter "C"
"C:/Users/Golcha/Desktop/Automation/geckodriver.exe"
Let me know if this solved your problem.
I had a similar problem but weirdly I was not able to execute the selenium script on both my drivers (chrome and firefox), I tried checking my setProperty method, my gecko driver path and chrome driver path. Lastly, I tried updating both my browser and it seems to be working now. (my current version of Chrome is 66 and my current version of my Firefox is 56.0).
I want to write couple of tests for a web page with Selenium and jUnit4, but I can't figure out how to make Firefox open the URL I need. Without System.setProperty(...) I'm getting 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. and browser never opens. Yet if I implement it the browser does open on a default start "new page", but the line driver = new FirefoxDriver(); and further never executes.
Below is the simplest code version of what I'm trying to achieve:
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
static String URL = "http://www.google.com";
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
//Following code never executes
driver = new FirefoxDriver();
//I'm not sure if this is how I'm supposed to open URL, but I never had this code executed.
driver.get(URL);
driver.quit();
}
}
UPDATED:
These links were helpful to solve the problem of proper geckodriver installation.
https://github.com/mozilla/geckodriver/releases
http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
Actually you need to set geckodriver.exe path instead of firefox.exe in this
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
So just replace geckodriver.exe path and try