0

I am new in selenium and trying to open https://google.co.in in the chrome browser through selenium (below is the code). But I am not able to see the chrome browser after running this code. Could someone tell me that what's wrong with this code.

Here is my code.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Test {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "E:\\Application\\chrome.exe");
        System.out.println("Loading...");
        WebDriver driver  = new ChromeDriver();
        driver.get("http://google.co/in");
        String appTitle = driver.getTitle();
        System.out.println("Application title is :: "+appTitle);
        driver.quit();
    }
}

And the output is...

Loading...
4
  • Are you saying that your program exits successfully without any error ? Or does it hangs after loading message? Commented Oct 14, 2016 at 3:33
  • No, program still running and stuck on line ' Driver driver = new ChromeDriver();' Commented Oct 14, 2016 at 3:59
  • 1
    You can write chromedriver.exe instead chrome.exe After downloading the chrome driver by default you'll get the driver with name chromedriver. now you can add .exe to the name Commented Oct 14, 2016 at 5:59
  • What is your operating system? I have had the same issue when I was using non english windows 10 O.S. When I switched on english windows 10 the selenium methods started working properly. Commented Jun 28, 2018 at 17:06

3 Answers 3

0

Download chromedriver from this link : http://chromedriver.storage.googleapis.com/2.24/chromedriver_win32.zip , unzip it & put chromedriver.exe in "E:\Application" and provide path to chromedriver in System.setProperty("webdriver.chrome.driver", "E:\\Application\\chromedriver.exe");

Sign up to request clarification or add additional context in comments.

Comments

0
System.setProperty("webdriver.chrome.driver", "E:\\Application\\chrome.exe");

Here E:\Application\chrome.exe is not your chrome driver.

Download the chrome driver of the version you need in your application.

Latest Release: ChromeDriver 2.24

Once you have the chrome driver , specify its location via the webdriver.chrome.driver system property (see sample below)

@Test
public void testGoogleSearch() {
  // Optional, if not specified, WebDriver will search your path for chromedriver.
  System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

  WebDriver driver = new ChromeDriver();
  driver.get("http://www.google.com/xhtml");
  Thread.sleep(5000);  // Let the user actually see something!
  WebElement searchBox = driver.findElement(By.name("q"));
  searchBox.sendKeys("ChromeDriver");
  searchBox.submit();
  Thread.sleep(5000);  // Let the user actually see something!
  driver.quit();
}

Comments

0

You can use a following library webdrivermanager

after using this, you don't need to download a driver for the specific browser.It will automatically download driver for you and setup.

In order to use WebDriverManager in a Maven project, first add the following dependency to your pom.xml:

<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.10</version>
</dependency>

Then you can let WebDriverManager to do manage WebDriver binaries for your application/test. Take a look to this JUnit example which uses Chrome with Selenium WebDriver:

public class ChromeTest {

protected WebDriver driver;

@BeforeClass
public static void setupClass() {
    ChromeDriverManager.getInstance().setup();
}

@Before
public void setupTest() {
    driver = new ChromeDriver();
}

@After
public void teardown() {
    if (driver != null) {
        driver.quit();
    }
}

@Test
public void test() {
    // Using Selenium WebDriver to carry out automated web testing
}

}

Notice that simple adding ChromeDriverManager.getInstance().setup(); WebDriverManager does magic for you:

It checks the latest version of the WebDriver binary file

It downloads the binary WebDriver if it is not present in your system

It exports the required Java variable by Selenium WebDriver

So far, WebDriverManager supports Chrome, Opera, Internet Explorer, Microsoft Edge, PhantomJS, or Marionette as follows:

ChromeDriverManager.getInstance().setup();
InternetExplorerDriverManager.getInstance().setup();
OperaDriverManager.getInstance().setup();
EdgeDriverManager.getInstance().setup();
PhantomJsDriverManager.getInstance().setup();
MarionetteDriverManager.getInstance().setup();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.