Running Selenium Webdriver Test In Google Chrome

You can read my THIS POST to know how to run selenium webdriver test of software application in Mozilla Firefox browser. As you know, webdriver software testing tool support Google Chrome browser too. You need to do something extra for launching webdriver test in in Google chrome browser. Let me describe you steps to launch webdriver test in Google Chrome for software web application.

Create selenium webdriver data driven framework from scratch @This Page.

Download ChromeDriver server
First of all, download latest version of ChromeDriver server for webdriver software testing tool. You can download it directly from https://sites.google.com/a/chromium.org/chromedriver/downloads. Current latest version for win32 is “ChromeDriver 2.15” as shown bellow.

Click on “ChromeDriver 2.15” link. It will take you to download page.

Click on link shown above to download chrome driver zip file. On completion of download, extract zip file to D:/ drive.

Now in eclipse, create new project with name = ‘chromeproject’ and create new class with name = ‘chromebrowser’. Don’t forget to select ‘public static void main(String[] args)’ method during new java class creation. Write code as shown bellow in class file.

Don’t know how to find and evaluate XPath in chrome?

package mytestpack;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class chromebrowser {

 public static void main(String[] args) {
  System.setProperty("webdriver.chrome.driver", "D:\chromedriver_win32\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.get("http://www.google.com");
  if (driver.findElement(By.xpath("//input[@name='q']")).isEnabled()) {
   System.out.println("Google search text box Is enabled.");
   driver.findElement(By.xpath("//input[@name='q']")).sendKeys("WebDriver Test successful.");
   driver.findElement(By.xpath("//button[@name='btnG']")).click();
   System.out.println("Google search completed.");
  } else {
   System.out.println("Google search test box Is Not enabled.");

  }
  driver.close();
 }
}

Look in to above example. I set path for Google chrome driver as System.setProperty(“webdriver.chrome.driver”, “D:\chromedriver_win32\chromedriver.exe”);

So now, your software web application’s test will run in Google chrome browser. Learn how to execute webdriver test in Internet Explorer browser in THIS POST.

39 thoughts on “Running Selenium Webdriver Test In Google Chrome

  1. i'm getting error as "The method SetProperty(String, String) is undefined for the type System" also my sytem is win64.

  2. Thanks for this very helpful post.
    I'm very new to Java…I've a que. regarding the 'import' line..what is it about? Why didn't have to download FireFoxDriver Server just like that for ChromeDriver?

    Thanks

  3. Hi,

    I am facing one problem here, as I run the above test i can see the below error. Can you help me in running the test without fail.
    error details

    Starting ChromeDriver (v2.3) on port 18396
    Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unable to discover open pages
    (Driver info: chromedriver=2.3,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 22.33 seconds
    Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
    System info: host: 'sys', ip: '14.99.186.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_71'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:171)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:160)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117)
    at chromeProject.Chromebrowser.main(Chromebrowser.java:12)

  4. hi am facing this error ,plz help me

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at test_project.test_class.main(test_class.java:13)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 1 more

  5. driver.findElement(By.xpath("//input[@name='q']")).sendKeys("WebDriver Test successful.");
    this code of line shows the below error please help me.
    The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)

  6. In above code I facing problem in "sendkeys" it showing The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String).

    I can't understand whats d meaning of this. Please reply !!!

  7. Even I had faced such issue with SendKeys.After updating to the latest version of the WebDriver, issue got resolved. We need to have latest version of Browser and WebDriver as well..

  8. t has a simple solution. Change your compiler compliance level from 1.4 to 1.7.

    Follow these steps in your eclipse:

    Right click on your java project and select Build Path -> Click on
    Configure Build Path…
    In project properties window, Click/select Java Compiler at the left
    panel
    At the right panel, change the Compiler compliance level from 1.4 to 1.7
    (Select which is higher version in your eclipse)
    Lastly Click on Apply and OK
    Now check your code. it will never show the same error.

  9. I have Got following error message – Can u Please Help

    Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 6290
    Only local connections are allowed.
    Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
    (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 1.02 seconds
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'narendragawas', ip: '192.168.1.97', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_73'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

  10. Hi I got the following error while run the script please help me…..

    Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: D:chromedriver_win32chromedriver.exe
    at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
    at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116)
    at tiyotesting.Citydropdownlist.main(Citydropdownlist.java:16)

  11. Hi I got the following error what should i do tell me.. please

    Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: D:chromedriver_win32chromedriver.exe
    at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
    at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116)
    at tiyotesting.Citydropdownlist.main(Citydropdownlist.java:16)

  12. I am getting the following error. Can someone please help me on how to proceed?

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at chromebrowser.main(chromebrowser.java:10)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 1 more

Leave a Reply

Your email address will not be published. Required fields are marked *