Reputation: 677
Asking because I'm following Guru99's time sensitive selenium course and the code that I have downloaded as part of my project will not run as a java application. It is supposed to be ran with only this code:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestScript01 {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
String baseUrl = "http://www.demo.guru99.com/V4/";
// launch Firefox and direct it to the Base URL
driver.get(baseUrl);
// Enter username
driver.findElement(By.name("uid")).sendKeys("xxxx");
// Enter Password
driver.findElement(By.name("password")).sendKeys("xx");
// Click Login
driver.findElement(By.name("btnLogin")).click();
}
}
However, I have added: import org.openqa.selenium.WebDriver;
and System.setProperty("webdriver.chrome.driver",
"C://selenium/chromedriver.exe");
I've also not included my real username and password in code above
I have downloaded Chrome driver to the selenium folder in my C drive
I was trying to run from firefox initially but was stuck on Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
errors, which I downgraded my firefox for as that worked for many on this site, but it was still giving me the same error so I switched to Chrome, which selenium seems to prefer. I'm using the latest version of Chrome and Firefox 47.0
I'm using selenium 3.6.0 and jdk 1.8.0_111
When trying to run as an application, according to the instructions, I seem to be in a loop where I keep getting this screen:
I have never had to select an option in order to run a selenium script before, not sure why I'm getting it now or what I'm supposed to select if any.
I have googled but it seems that most instructions for running selenium tests do not include this pop-up. I thought that instantiating a new WebDriver
object and selecting the right imports were enough, what am I missing?
Upvotes: 1
Views: 736
Reputation: 193338
You havn't mentioned the Selenium
, ChromeDriver
, Chrome Browser
and JDK
versions. Assuming you are using the latest version of Selenium
, ChromeDriver
, Chrome Browser
and JDK
, I would suggest a few steps as follows:
import org.openqa.selenium.*;
always use import org.openqa.selenium.WebDriver;
and the required ones.While working with Selenium 3.x (Java)
it is mandatory to mention the following line :
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
In this line you have to either use single front slashes /
or you have to use escaped back slashes \\
The screen with Select Java Application
indicates there are multiple overlapping imports
in your project or methods
from overlapping jars
. We need to keep only the used imports
in your script & used jars
in your project and remove the other imports
/jars
from your script
/project
to keep it simple.
From your IDE
take a Project -> Clean
for all the projects and keep Build Automatically
selected.
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
can arise for many reasons. The best remedy is to uninstall
the Browser
with Revo Uninstaller
, Run CCleaner
to wipe out all the rotten OS stuffs and take a system reboot and trigger your Test
.Upvotes: 1