I am running the following code in Eclipse but my Google Chrome is not launching.
The configurations are:
Eclipse IDE for Java Developers
Version: 2019-12 (4.14.0)
Have taken latest versions for GC driver.
The same code and config is working for another laptop but not on mine. Have re-installed the application several time.
All the libraries available on internet have also been imported.
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.*;
public class FirstTestCase {
public static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.firefox.driver", "C:\\Users\\WC-Parul\\Downloads\\geckodriver-v0.26.0-win64.zip");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
// Launch the Online Store Website
// driver.get("http://www.shop.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
// Close the driver
// driver.quit();
}
}
you say Chrome? you are not use
FirefoxDriver driver = new FirefoxDriver();
you should
WebDriver driver = new ChromeDriver();
and you should download chromedriver.exe
Hope it helps you
If not, please take a screenshot "Java Build Path"
Extract C:\\Users\\WC-Parul\\Downloads\\geckodriver-v0.26.0-win64.zip and provide geckodriver.exe path
Something like
System.setProperty("webdriver.firefox.driver", "C:\\Users\\WC-Parul\\Downloads\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
Make sure your downloaded correct version of geckodriver
If you want to run the code on Chrome browser then download compatible chromedriver.exe from here as per your chrome browser version and use below code:
System.setProperty("webdriver.chrome.driver", "drive_path\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
Related
I have just configured Selenium for Java on Eclipse on a new PC (have configured without issue for a number of times in the past) and can run a sample code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AutoLogin {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C://pathtodrive//chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Open Register
driver.get("https://google.com");
// Maximize browser
driver.manage().window().maximize();
}
}
The above code works perfectly and could see google.com open in the browser window. Now I wanted to change some of the default options like default download directory, certificate check etc. I could see the ChromeOptions.class under imported client-combined-3.141.59.jar
But when I write
import org.openqa.selenium.chrome.ChromeOptions;
the eclipse shows error
the import org.openqa.selenium.chrome.ChromeOptions cannot be resolved
please advise what could be wrong? and which configuration I am missing
os: windows 10 64 bit eclipse: Helios Service Release 1
(Build id: 20100917-0705 ) 32 bit java: jre1.8.0_261 32 bit
In addition to the specified import, the driver must be properly initialized. In the code below, it works. That is, first we specify the options, then we use this variable to create a web driver instance.
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito", "headless", "disable-gpu", "window-size=1366,768", "ignore-certificate-errors");
newWebDriver = new ChromeDriver(options);
And of course the corresponding import.
import org.openqa.selenium.chrome.ChromeOptions;
I have this java class code in package ChromeBrowser (That I made)
package ChromeBrowser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchChrome{
public static void main(String[] args){
String url = "<<<The URL I want to open>>>";
WebDriver driver = setUp();
launch(driver, url);
}
static void launch(WebDriver driver, String url) {
driver.navigate().to(url);
}
static WebDriver setUp() {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
return driver;
}
}
But when I run it, I get the error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Steps I've taken:
I have chrome installed.
I have downloaded the webdriver, and checked it is in C:\Selenium\chromedriver.exe
java jdk is in environment path
webdriver is in environment path, added in attempt to solve, didnt work
The code compiles and runs on my colleague's machine
Expected result:
Chrome browser opens at The URL I want to open.
Do I need to define the path to the chrome executable at C:\Program Files (x86)\Google\Chrome\Application?
Help me please thanks in advance.
EDIT:: I've tried most of the other stack overflow questions with the name of the error, but they haven't helped.
I am not really sure what the issue is but you can try below suggestions-
System.setProperty("webdriver.chrome.driver", "C:/Selenium/chromedriver.exe");
This could be a compatibility issue between the 'selenium', 'Chrome browser version' and 'chrome driver' version that you are using. If
you are using Selenium 2.53, then using chrome driver 2.25 should work
for you.
Download latest chrome driver from seleniumhq.org
Add 127.0.0.1 localhost to C:\Windows\System32\drivers\etc\hosts.
Seems like there is some issue with creating session with Firefox. Try the following code and test using Chrome browser.
You need to download the executable driver from: https://sites.google.com/a/chromium.org/chromedriver/downloads
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver",
"/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver = new ChromeDriver();
//Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.get("http://www.calculator.net/");
//Maximize the browser
driver.manage().window().maximize();
or Check the network settings (proxy, firewall, antivirus software), something is blocking
connections between selenium and the browser.
For ex my chrome when dropped in the commpand prompt gives me the path
- /Applications/Google\ Chrome.app
I set
System.setProperty("webdriver.chrome.driver", "/Applications/Google/Chrome.app");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
But it doesnt work, same with firefox. I used a lot of suggestions already given but none seems to work. Can someone pls let me know if there is something to be added?
Why have you used "/Applications/Google/Chrome.app". You would need to provide the path of the driver only, not the browser. Below is the code for Firefox, but you would need to download and configure GeckoDriver (for latest version of FF and Selenium 3.x)
public class FirefoxTest {
#Test
public void FirefoxTest_Test1() {
System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Check this link for complete details for downloading and setup of Geckodriver with Firefox - http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
For Chrome: Need to Download fresh Chrome Driver from http://chromedriver.storage.googleapis.com/index.html?path=2.24/
and mention local system path up to chomedriver.exe
System.setProperty("webdriver.chrome.driver","G:\\ravik\\Ravi-Training\\Selenium\\Drivers\\cd\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriver d1 = new ChromeDriver(capabilities);
For FF: if your firefox version is latest(46.0 or above) then user geckodriver along with selenium 2.53.0 jar files. download geckodriver form https://github.com/mozilla/geckodriver/releases and then save it as "wires" in your local system. mention local system path up to wires.
System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
WebDriver driver = new MarionetteDriver();
Hope this could be helpful.
The easiest way to use chrome driver is.. download and place the driver into the bin folder of your project. no need to set the path of the driver location
i am running the project file on the same system on which i am testing
i am using selenium web driver and eclipse for testing the project but error is shown, when i run the selenium script for testing login page.
**error** :
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
l,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},
"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1462864767739,"updateDate":1462864767739,"applyBackgroundUpdates":1,"skinnable":true,"size":22012,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"
{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"46.0.1","maxVersion":"46.0.1"}],"targetPlatforms":[],"seen":true}
so after this i had set the proxy
and tried but the result was same
but when i tried to copy the link and manually pasted it in Mozilla and searched it was successfully showing the login page
CODE SELENIUM
Package TESTING
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class demo {
`public static void main(String[] args) {
WebDriver driver= new Firefox Driver();
driver.get("localhost:8080/Chaitanya");
driver.findElement(By.name("username")).send Keys("login");
driver.findElement(By.name("login.password")).send Keys("password");
`
I had same issue in my recent project (FYI: issue is caused by port) , fixes for this is:
Try to update latest version of selenium, this should fix it. if not, dirty work around for this is
WebDriver driver;
try {
driver = new FirefoxDriver();
}
catch(Exception e) {
driver = new FirefoxDriver();
}
There few typo error....
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class demo {
public static void main(String[] args) {
WebDriver driver= new FirefoxDriver();
driver.get("http://localhost:8080/Chaitanya");
driver.findElement(By.name("username")).sendKeys("login");
driver.findElement(By.name("login.password")).sendKeys("password");
}
if Still same error occurs.
Please update Selenium Jar to latest( http://www.seleniumhq.org/download/ ), and update Firefox browser to latest version.
I'm trying to launch chrome with Selenium Webdriver and used the following code:
System.setProperty("webdriver.chrome.driver",
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.yahoo.com");
Chrome browser opens but is not proceeding further. What could be the reason for the following error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
You are incorrectly starting up the driver
webdriver.chrome.driver is supposed to be the path to the driver that you've downloaded and not Chrome's physical location.
First you need to download chrome driver file from this link and than import its JAR to the package in eclipse.
Download the link from here
Then you will have to import it in your program.
import org.openqa.selenium.chrome.ChromeDriver;
and than make a driver instance
driver = new ChromeDriver();
Download the external JAR of chrome
In eclipse :: right click on the respective package(in the package explorer) and click on the properties. Go to Java build path and add external jars. Now add the jar file of chrome . and than follow the steps i wrote in the ans which was to import the chrome driver and creating an instance
Follow these steps in the photograph.
1)
select your file from here and right click
Below snippet shows how you can open chrome browser using selenium webdriver.
public static void main(String[] args) {
//Creating a driver object referencing WebDriver interface
WebDriver driver;
//Setting the webdriver.chrome.driver property to its executable's location
System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
//Instantiating driver object
driver = new ChromeDriver();
//Using get() method to open a webpage
driver.get("https://stackoverflow.com");
//Closing the browser
driver.quit();
}
Use the latest versions of ChromeDriver.
Source|
http://chromedriver.storage.googleapis.com/index.html
You need to setup your browser settings first. Try below-mentioned code if it helps:
public void setup ()
{
System.setProperty("webdriver.chrome.driver", "C:\\**PATH**\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("--js-flags=--expose-gc");
options.addArguments("--enable-precise-memory-info");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("test-type=browser");
options.addArguments("disable-infobars");
driver = new ChromeDriver(options);
driver.manage().deleteAllCookies();
}
You'll need to import files by hovering on error lines.