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 comments:

  1. Is ChromeDriver not available for win64???

    ReplyDelete
    Replies
    1. http://chromedriver.storage.googleapis.com/index.html?path=2.3/

      Delete
  2. Very clear & understandable

    ReplyDelete
  3. beginnerSeleniumn2 April 2014 at 16:11

    Awesome post

    ReplyDelete
  4. Very Nice post
    What path we set in linux 32 bit system. My OS is Ubuntu 12.04 LTS
    directly we set home path or any other.

    ReplyDelete
  5. Hi Pls send me code of above example

    ReplyDelete
  6. nice touturial

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

    ReplyDelete
  8. good effort. Can I get code please?

    ReplyDelete
    Replies
    1. Please fill this form
      http://software-testing-tutorials-automation.blogspot.com/p/request-free.html

      Delete
  9. This comment has been removed by the author.

    ReplyDelete
  10. It is an effective tutorials for beginners. Thanks a lot

    ReplyDelete
  11. very very helpful post.. good luck for your good work

    ReplyDelete
  12. 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

    ReplyDelete
    Replies
    1. You not need driver server file for firefox. You need It for other browsers ike chrome, IE, etc..

      Delete
  13. The link as provided for Chrome driver download doesnt have the file at present, can this be updated to http://chromedriver.storage.googleapis.com/index.html?path=2.14/

    ReplyDelete
  14. 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)

    ReplyDelete
  15. 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

    ReplyDelete
    Replies
    1. How did you resolve this error? I am facing same issue.

      Delete
    2. Check your JDk version ,,Update with Recent JDK version,It may work

      Delete
  16. thanks a lot very effective for beginnners................

    ReplyDelete
  17. 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)

    ReplyDelete
    Replies
    1. driver.findElement(By.id("type_field_name_here")).sendKeys("Web Driver Test Succesful");

      Delete
    2. 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.

      Delete
  18. 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 !!!

    ReplyDelete
  19. 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..

    ReplyDelete
  20. Is ChromeDriver not available for win64 ???

    ReplyDelete
  21. 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)

    ReplyDelete
  22. 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_win32\chromedriver.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)

    ReplyDelete
  23. 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_win32\chromedriver.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)

    ReplyDelete
  24. 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

    ReplyDelete