org.openqa.selenium.WebDriverException: unknown error: net::ERR_CONNECTION_REFUSED - java

When I try to run my project using Selenium and Java, I am getting this error and I do not know how to solve it. This is happening on VSCode and the SO is Windows 11.
org.openqa.selenium.WebDriverException: unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=108.0.5359.125)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
This is the code I created:
WebDriver browser = new ChromeDriver();
browser.navigate().to("http://localhost:8080/leiloes");
browser.quit();
I appreciate your help.
Marcelo

You need to set the property of webdriver like below, and you can use get instead of driver.get("http://www.facebook.com");
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path of the exe file\\chromedriver.exe");
// Initialize browser
WebDriver driver = new ChromeDriver();
// Open facebook
driver.get("http://www.facebook.com");
// Maximize browser
driver.manage().window().maximize();
}
}

Related

'geckodriver.exe binary cannot be found in PATH' when attempting to automate firefox browser with Appium

I have been scratching my head with this issue, I can get chrome app running but firefox will not. I have added geckodriver.exe to my path variables (both user and system), install Firefox 64bit, and done all prerequisites to run appium tests (including reading this appium guide). I realise through searching the web this is a recent appium update, so I feel a bit like I'm in uncharted territory.
Below is the code I have along with the error message when attempting to run (TestNG)
public class test {
public AndroidDriver<MobileElement> driver;
public WebDriverWait wait;
#BeforeMethod
public void setup() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Jack\\Downloads\\drivers\\geckodriver.exe");
caps.setCapability("deviceName", "sdk_gphone_x86");
caps.setCapability("udid", "emulator-5554"); //DeviceId from "adb devices" command
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "11.0");
caps.setCapability("automationName", "Gecko");
caps.setCapability("browserName", "firefox");
caps.setCapability("skipUnlock", "true");
caps.setCapability("noReset", "false");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
wait = new WebDriverWait(driver, 10);
}
#Test
public void basicTest() throws InterruptedException {
TimeUnit.SECONDS.sleep(5);
}
#AfterMethod
public void teardown() {
driver.quit();
}
}
Error
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: geckodriver.exe binary cannot be found in PATH. Please make sure it is present on your system
Server Log
Go to Environment variables->System variables->Path variable->Click on edit->Give the path of geckodriver.exe folder(do mention the folder name where geckodriver.exe resides) Ex:- C://Users//Downloads//GeckodriverFolder
Create another system variable "geckodriver" and provide the same path of geckodriver.exe stored folder.
Apply changes and restart IDE and execute the testcase.

How do I setup Selenium WebDriver with Java?

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

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu

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.

not able to run the script in eclipse

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

Using Chrome Driver with Selenium 2

I'm trying to use Chrome Drive to execute some of my tests, which are working perfectly with Firefox, but I'm not being able to execute them, I'm already verified the requirements, which are the location of Chrome, Version 12 or higher, and things like that, but anyway still not working correctly, the way to call the driver is:
WebDriver fd = new ChromeDriver();
fd.get("url");
and then searching some elements, but nothing is working, the error message is:
Exception in thread "main"
org.openqa.selenium.WebDriverException:
Couldn't locate Chrome. Set
webdriver.chrome.bin System info:
os.name: 'Windows XP', os.arch: 'x86',
os.version: '5.1', java.version:
'1.6.0_18' Driver info:
driver.version: ChromeDriver at
org.openqa.selenium.chrome.ChromeBinary.getChromeBinaryLocation(ChromeBinary.java:220)
at
org.openqa.selenium.chrome.ChromeBinary.getCommandline(ChromeBinary.java:121)
at
org.openqa.selenium.chrome.ChromeBinary.prepareProcess(ChromeBinary.java:67)
at
org.openqa.selenium.chrome.ChromeBinary.start(ChromeBinary.java:109)
at
org.openqa.selenium.chrome.ChromeCommandExecutor.start(ChromeCommandExecutor.java:373)
at
org.openqa.selenium.chrome.ChromeDriver.startClient(ChromeDriver.java:65)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:85)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:25)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:43)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:53)
at
equifax.qa.test.NewTests.access.main(access.java:11)
Please if anyone can help me would be great.
I was able to get this to work by launching the selenium server like this:
java -jar selenium-server-standalone-2.0rc2.jar -Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe
(Running Windows 7 64bit, Chrome 12, selenium server rc2)
Download the ChromeDriver.exe from http://code.google.com/p/selenium/downloads/list then add the system property like so:
System.setProperty("webdriver.chrome.driver", "...\chromedriver.exe");
Use this for Chrome
Step-1 Download Chrome driver from location
Step-2 Use Testng Framework
#BeforeClass
public void setUp() throws Exception
{
System.setProperty("webdriver.chrome.driver", "D://Work-Selenium//chromedriver_win32//chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "http://google.com";
driver.get(baseUrl);
}
Just download the chromedriver_win32_13.0.775.0.zip and selenium-server-standalone-2.0rc3.jar from [http://code.google.com/p/selenium/downloads/list][1]
Unzip the chromedriver_win32_13.0.775.0.zip into a folder, Eg. C:/drivers/chrome/, so that the chromedriver.exe is located at C:/drivers/chrome/chromedriver.exe.
Register the node against the hub on port 6668 (for example)
java -jar selenium-server-standalone-2.0rc3.jar -role webdriver -hub http://hubUrlHostname:4444/grid/register -port 6668 -browser "browserName=chrome,version=13.0,platform=windows" -Dwebdriver.chrome.driver=C:\drivers\chrome\chromedriver.exe
If you access to
http://hubUrlHostname:4444/grid/console
you should see the Chrome driver registered.
Have you made sure that you have downloaded the Chrome driver from http://code.google.com/p/selenium/downloads/list and placed it in your PATH?
have a look at http://code.google.com/p/selenium/wiki/ChromeDriver for more details
You can set the capabilities to point to the binary of the browser to be launched.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "/usr/lib/chromium-browser/chromium-browser");
WebDriver driver = new ChromeDriver(capabilities);
For ex:- Chromium Browser(33.0.1729.0 )works fine with ChromeDriver 2.7 and not the with the older ones.
You can choose from all the chromedriver version available from the link below:- http://chromedriver.storage.googleapis.com/index.html
So try to use the browser version supported by the chromedriver.
If you are using Maven Project. Follow the below steps
Download the latest chromedriver.exe from this link.
Create a drivers folder in test. It should look like this src/test/resources/drivers
Move the chromedriver.exe to the above path in step 2
Use the below code for before creating chrome driver object
System.setProperty("webdriver.chrome.driver",
Thread.currentThread().getContextClassLoader().getResource("drivers/chromedriver.exe").getFile());

Categories