I have a question on how to start using Selenium WebDriver with Java.
Here is my code:
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MyClass
{
public static void main (String[] args)
{
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
}
}
I then get the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\MrJPG\eclipse-workspace\Project IG Bot\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: Package IGBotPackage not found in module
Does anyone know the solution to this? I have tested adding the external jars from Selenium in both the Modulepath and Classpath. However, both seem to have the same result and error.
you need add this
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
chromedriver.exe is your chromedriver.exe path //download chromedriver.exe
maybe
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
Need to be the same as your chrome version
if your chrome is '80.0.3987.106'
need at least these are the same '80.0.3987'
Hope that helps you
Please use Which ChromeDriver version is compatible with which Chrome Browser version? to download right version of chromedriver exe.
Place above exe in any(e.g. D:\) path and use below code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
Related
I'm new to Selenium and I can't run the simplest program:
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("https://google.com");
HelloWorld.LOGGER.info(driver.getTitle());
}
The error I receive :
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:754)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
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.<init>(ChromeDriver.java:123)
at com.genesys.testing.topicsDefinitionUI.HelloWorld.main(HelloWorld.java:20)
After reading the exception above I saw in this website a solution that didn't work for me :
public static void main(String[] args) {
System.setProperty("WebDriver.Chrome.driver","/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com");
HelloWorld.LOGGER.info(driver.getTitle());
}
The error I received :
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:754)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
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.<init>(ChromeDriver.java:123)
at com.genesys.testing.topicsDefinitionUI.HelloWorld.main(HelloWorld.java:20)
I'm working on MacOS - Catalina, my IDE is Intellij and this is a Maven Project.
Tried to switch the second argument of System.setProperty() function to numerous variations of the path with no success.
What am I missing ?
To run your code on chrome browser you need to set path of chromedriver. ypu haavee specified wrong path of chrome driver in your code
System.setProperty("webdriver.chrome.driver","chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com");
System.out.println(driver.getTitle());
Check your browser version and download chromedriver from the below link:
https://chromedriver.chromium.org/downloads
So, my friend here above #Rock was right.
I did need to download the chrome driver.
But, because I'm working on macOS Catalina, I had to change the permission for the chromedriver file manually.
With the help from this issue : MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser
This is how the code looks like now :
public void firstTest() {
System.setProperty("webdriver.chrome.driver","/Users/raziv/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
System.out.println(driver.getTitle());
}
And it's working fine
My Code :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstAutomation {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\sony\\Downloads\\chromedriver_win32.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://wwww.google.com");
}
}
Exceptions
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\sony\Downloads\chromedriver_win32.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
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:329)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at FirstAutomation.main(FirstAutomation.java:8)
Please follow the below steps to add the Chromedriver.exe
Right Click on your Selenium Project -> Build Path -> Configure Build Path -> Libraries -> Add External Class Folder
Note: kindly cross-check the chrome driver Path location in your pc and make sure the chrome driver version and google chrome version's match each other
Link to download the latest Chrome Driver
I hope the above process Works
Thanks to Vikas Dadi. I had downloaded chrome driver of 80 version and the actual browser being used on the laptop was 79, hence the error. But now it is working fine after deleting the driver and reinstalling the driver of the same version.
I am new in Automation testing.
Had created a simple program to Open URL in Firefox browser. Browser is getting opened without URL.
Someone please help.
package sanitytest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Adminlogin {
public static void main(String[]args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/login.php");
}
}
I am using Firefox version :- 47.0.1
eclipse mars version :- 4.5.0
Selenium webdriver version :- 2.51
For Mozila Firefox till version 46.x it was the legacy browser and we didn't need gecko driver. Mozila Firefox from version 47.x onwards comes with Marionette, which is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox. Can be donwloaded here: https://github.com/mozilla/geckodriver/releases and needs selenium 3.x.
So, either downgrade FF to version 46.x, or use latest selenium binding with geckodriver + latest FF
Unfortunately Selenium WebDriver 2.51.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued.
Try using firefox 46.0.1. It best matches with Selenium 2.51
https://ftp.mozilla.org/pub/firefox/releases/
try the following code its working
package automation ;
import java.util.concurrent.TimeUnit
enter code here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) throws InterruptedException {
//Object webdriver;
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\user\\Downloads\\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");
String i = driver.getCurrentUrl();
System.out.println(i);
//driver.close();
}
}
if its not working http://www.seleniumhq.org/download/ here download java 3.4.0
then in eclipse, right click your project-->properties-->java build path--> liberies-->add external JARS..
enter image description here
Attempting to execute the following Selenium script results in a WebDriverException:
package package1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Class1 {
public static void main(String[] args) {
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.close();
}
}
The exception thrown is
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:99)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:80)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at package1.Class1.main(Class1.java:12)
Why is this happening?
Used version- 1.8.0_101 java file
Neon eclipse
2.53 selenium jar file
You need to start the selenium server with the Firefox driver before running the test
My code is not launching browser.
Project show running for a long time, but nothing happens. I pushed print and observed that WebDriver driver = new ChromeDriver(); is not getting executed.
package seleniumautomation;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class seleniumautomation {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:/selenium_java/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://www.zaakpay.com/");
}
}
After some debugging, I am getting this new error:
I added manifest_vesion, but in every run, it is generating a new file and i am again getting same error.
Download jar from: http://chromedriver.storage.googleapis.com/index.html?path=2.23/
System.setProperty("webdriver.chrome.driver",
"<Downloaded file location>");
WebDriver driver = new ChromeDriver();
driver.get("https://www.zaakpay.com/");
Then, it will work.
To use Chrome Browser needs to System.setPropert("webdriver.chrome.driver","PATH")
The ChromeDriver is maintained / supported by the Chromium project iteslf. WebDriver works with Chrome through the chromedriver binary.
Download Link of ChromeDriver : LINK
You need to add chromedriver.exe(can be downloaded from http://www.seleniumhq.org/download/) to your project. Along with it, you need to add following lines in your code:
System.setProperty("webdriver.chrome.driver", PATH_TO_EXE_FINAL);
capabilities= DesiredCapabilities.chrome();
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
Use following code snippet to launch chrome driver.
System.setProperty("webdriver.chrome.driver", PATH_TO_EXE_FINAL);
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-extensions");
opt.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(opt);
I solved the issue by changing my OS windows 10 language to english. selenium methods can not execute some other languages. If in both IE, geckodriver and chrome you are having the same issue it is language problem I can asuure you
enter image description hereTrying to check the version you installed in web driver and the version you currently use in you chrome