×

Selenium WebDriver - Google Chrome Browser

Selenium WebDriver - Google Chrome Browser

In this tutorial, we will learn how to run our Selenium Test Scripts in the Google Chrome Browser.

To implement the WebDriver protocol with the help of an executable file, which is called as the ChromeDriver.exe.

The above executable file starts the server in our system that is responsible for running our test scripts in the Selenium WebDriver.

And we will create one sample test case in the same test suite (new_test), which we create in the previous tutorials.

Step1:

  • Firstly, right-click on the src folder and create a new Class File from New ? Class.
Selenium web driver - Google Chrome Browser
  • And give our Class name as test_chrome and click onthe Finish button.
Selenium web driver - Google Chrome Browser 1

Step2:

Now, go to the selenium community and download the Chrome driver server. In the Selenium community, we will find the third party driver division. And click on the link beside the Google Chrome driver.

                                              Or

Directly open the below link, it will navigate you to the download page of Chrome driver in your browser.

https://sites.google.com/a/chromium.org/chromedriver/downloads

Step3:

If you click on the above link, it will redirect you to the Current releases page where you can download the operating system, which you are working currently on.

Selenium web driver - Google Chrome Browser 2
  • Click on the chromedriver_win32.zip link and download it for the Windows platform.
Selenium web driver - Google Chrome Browser 3
  • Download the zip file into your local system, and unzip the folder, it will generate chromedriver.exe file automatically.
Selenium web driver - Google Chrome Browser 4

Step4:

Run the server before launching the Chrome browser, with the help of System.property,

Syntax:

System.SetProperty(“key”, ”value”);

To set the system property for the Chrome driver in real-time where

Key = “webdriver.chrome.driver”

And the path of our ChromeDriver.exe file to invoke the ChromeDriver class.

Value=”C:\Users\JTP\Downloads\chromedriver_win32\chromedriver.exe"

Note: Make sure that, while copying a path for the chroedriver.exe file, it should always be in a double slash (//).

Sample code for system property:

// System Property for Chrome Driver
System.setProperty("webdriver.chrome.driver","C:\Users\JTP\Downloads\chromedriver_win32\chromedriver.exe");  
// create an object for ChromeDriver class
WebDriver driver=new ChromeDriver();   

Let us see one example where we will try to automate the following scenarios in the Google Chrome browser.

Steps Action Method Used Input Excepted Result
1. Open the Google Chrome Browser. System.setProperty()   The Google Chrome browser must be opened.
2. Navigate to the Given URL of the website. get() https://www.tutorialandexample.com The home page window must be displayed.
3. Maximize the browser.       The browser window should be maximized.
4. Identify the Angular 8 tutorials from the latest tutorial section.     The angular 8 tutorials should be identified in the latest tutorial section.
5. Close the Browser. close()   The browser should beterminated.

Here is the sample code for the above example.

package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class test_chrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\Users\JTP\Downloads\chromedriver_wi32\chromedriver.exe");
// create driver object for Chrome browser
WebDriver driver=new ChromeDriver();
// Launch the Website
driver.navigate().to("https://www.tutorialandexample.com");  
//Maximize the browser window
driver.manage().window().maximize();  
 System.out.println("window size is maximized");
// Click on the angular 8 tutorial link
driver.findElement(By.xpath("//a[contains(text(),'Angular 8 Tutorial')]")).click();
System.out.println("angular 8 tutorial page is opened");
//close the browser
driver.close();
System.out.println("existing browser is closed");
}
}

Now, right-click on the Eclipse code and select Run as ? Java Application.

The output of the above test script would be displayed in the Google Chrome browser.

The output of all print command of the above test script would be displayed in the Eclipse console window.

Selenium web driver - Google Chrome Browser 5

The output of all print command of the above test script would be displayed in the Eclipse console window.

Selenium web driver - Google Chrome Browser 6

 

 


Related Topics

Selenium WebDriver-CSS Selector: Tag and ID

Selenium WebDriver-CSS Selector: Tag and ID We will locate the web element with the help of tag and id CSS selector in this section of the tutorials Where Tag and id are...

4 minutes read.

CSS Selector: Class in selenium IDE

CSS Selector: Class Identify a web element with the help of Class as a CSS Selector is like using id attribute. The only difference between Class and id is in their...

2 minutes read.

Drawback or Limitations of Selenium

Drawback or Limitations of Selenium Followings are the Drawback or limitations of Selenium:- Drawback /LimitationsDescriptionDesktop applications cannot be automated by Selenium.To test the desktop application, we have tools like Test Complete, Winnium, and...

2 minutes read.

Selenium WebDriver- Microsoft Edge Browser

Selenium WebDriver- Microsoft Edge Browser: In this tutorial, we will learn how to launch the Microsoft Edge browser in the Selenium WebDriver. Before we start automating our test script with Microsoft Edge...

4 minutes read.

WebDriver-Tag Name Locator

Selenium WebDriver-Tag Name Locator The tag name locator is used along with the findElements() method to identify multiple similar elements in the UI. It is used to locate the web element with...

3 minutes read.

Mouse and Keyboard Controls in Selenium WebDriver

Mouse and Keyboard Controls in Selenium WebDriver In this tutorial, we will learn about how to handle mouse and keyboard event using action class in selenium WebDriver. Action Class in Selenium WebDriver: Action...

13 minutes read.

Selenium WebDriver - Firefox or Gecko (Marionette) browser

Selenium web driver-Firefox or Gecko (Marionette) browser In this tutorial, we are going to learn how to run the Selenium WebDriver test script in the Firefox Browser using the Gecko Driver. Before going...

4 minutes read.

WebDriver-Class Name Locator

WebDriver-Class Name Locator In this tutorial, we will learn about the Class name locator of selenium WebDriver. The Class Name locator is used to identify any element in UI based on the...

4 minutes read.

Selenium WebDriver- Checkbox handling

Selenium WebDriver- Checkbox handling In this tutorial, we will be learning about handling the checkbox in selenium WebDriver. Let us take one example to give you a better understanding of Checkbox handling,...

4 minutes read.

Name Locator in Selenium IDE

NAME LOCATOR: It is used to find the name in the web element. If we have multiple web elements of the same name, then the first matched element would be returned. Open the...

3 minutes read.

Selenium WebDriver installation

Installation Steps of Selenium WebDriver In this tutorial, we will see the process of selenium webdriver installation. Selenium WebDriver installation process is done in four Stages: Java Installation (version 8 or higher version) Eclipse...

4 minutes read.

Selenium WebDriver - Browser Controls Commands

Selenium WebDriver - Browser Controls Commands WebDriver includes operations like opening a browser, fetch the title, and closing the browser, etc. Some of the most commonly used Browser controls commands for Selenium WebDriver...

6 minutes read.

Selenium WebDriver-XPath Locator

Selenium WebDriver-XPath Locator The locators can make the object identification of all the selenium tools. There are eight locators available in selenium web driver, but most of the time we go for...

14 minutes read.

Selenium WebDriver-CSS Selector locator

Selenium WebDriver-CSS Selector locator A CSS selector is used to identify the web element based on their “# id” and “. Class”, Html tags, and attributes. A CSS stands for Cascading Style...

1 minute read.

Selenium IDE Tutorial for Beginners

Selenium IDE Introduction Selenium IDE stands for Integrated Development Environment. Selenium-IDE is released in 2006 and developed by SHINYA [JAPAN] THOUGHTWORK Company. Selenium IDE implemented as a Firefox plug-in, and concedes the record, edit, and debug tests....

2 minutes read.

Selenium WebDriver Commands

Selenium WebDriver Commands: As we learn previously in the Selenium-IDE tutorial, Selenium commands are the set of commands that are used to run a Selenium test script. But whereas, Selenium WebDriver had...

2 minutes read.

Selenium WebDriver – Window handling

Selenium WebDriver – Window handling In this tutorial, we will understand how we can handle the window, multiple windows, and pop-ups in selenium WebDriver. We have different types of window, and pop-ups...

7 minutes read.

WebDriver Interface | Class Diagram

WebDriver interface/class diagram: The interface of WebDriver includes the following stages, which is as follows: Search Context Web driver Remote web driver Driver class Search Context  The first interface of the web driver class is search Context,...

2 minutes read.

Selenium WebDriver-CSS Selector: Substring Matching

CSS Selector: Substring Matching Selenium WebDriver In this tutorial, we will learn how to identify the web element using the substring method. A Sub-string contains three methods for identifying the web element...

9 minutes read.

Selenium vs QTP

In this section, we are comparing the most frequently used automation tool –Selenium and QTP. Selenium and QTP have relative advantages over each other- FeaturesSeleniumHP QTPLicensingSelenium is an open-source testing tool....

3 minutes read.