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
Related
I am getting a complilation error when I try to run Selenium Webdriver.
I am using Eclipse and Java inside Eclipse.
I:
Went ahead and downloaded Selenium Server (4.3.0), the language-specific client drivers Java (4.3.0), and the stable release of the latest chrome drivers (got it from here - https://chromedriver.storage.googleapis.com/index.html?path=103.0.5060.134/). I had to download the 32 bit version even though my computer is 64 bit, but I only saw a 64 bit version for Windows.
Configured build path and added external jars to build path from the Selenium server file I downloaded.
The code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstSeleniumTest {
WebDriver driver;
public void launchBrowser() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\zachw\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.amazon.in/");
}
public static void main(String[] args) {
FirstSeleniumTest obj = new FirstSeleniumTest ();
obj.launchBrowser();
}
}
}
and keep getting this error:
Error: Unable to initialize main class FirstSeleniumTest
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Can anyone tell me why I am getting this compilation error and how to fix it?
Error:
Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist
Code trials:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Hello {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\91831\\OneDrive\\Desktop\\eclipse-workspace\\geckodriver.exe");
System.out.println("Hello");
WebDriver driver = new FirefoxDriver();
driver.get("http:\\www.amazon.in");
}
}
This error message...
Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist
...implies that the WebDriver executable doesn't exists at the mentioned location.
You have mentioned:
System.setProperty("webdriver.gecko.driver", "C:\\Users\\91831\\OneDrive\\Desktop\\eclipse-workspace\\geckodriver.exe");
As you are using windows operating system, ensure that you have downloaded GeckoDriver with .zip extension from the release location, unzipped the executable binary and placed geckodriver.exe within C:\\Users\\91831\\OneDrive\\Desktop\\eclipse-workspace sub-directory.
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");
I have tried this code in eclipse :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class auto {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.easybooking.lk/login");
//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
}
}
On execution I got this error :
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /root/Desktop/jarselenium/geckodriver.exe
How can i set geckodriver location in ubuntu?
As you are using Linux based System while specifying the absolute path of the GeckoDriver you have to trim the extension part i.e. .exe part as follows :
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
Update
As you are still seeing the error ensure that :
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users. (chmod 777)
Execute your #Test as a non-root user.
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