Testing With Selenium WebDriver (68 Blogs) Become a Certified Professional
AWS Global Infrastructure

Software Testing

Topics Covered
  • Testing With Selenium WebDriver (58 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

How to Run Selenium in Chrome Browser?

Published on Aug 02,2019 721 Views
A tech enthusiast in Java, Image Processing, Cloud Computing, Hadoop. A tech enthusiast in Java, Image Processing, Cloud Computing, Hadoop.
6 / 16 Blog from Selenium IDE Fundamentals

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

Testing the system is a challenging task and you need a tool which can help you in this process. Selenium is one such tool which mainly deals with website testing. In this article, I will tell you how to run Selenium in Chrome Browser.

Let’s get started!

What is Selenium?

Selenium - How to run selenium on chrome - EdurekaSelenium is an open-source portable framework used to automate testing of web applications. It is highly flexible when it comes to testing functional and regression test cases. Selenium test scripts can be written in different programming languages like JavaPython, C# and many more. These test scripts can run across various browsers like Chrome, Safari, Firefox, Opera and also provides support across various platforms like Windows, Mac OS, Linux, Solaris.

Selenium also supports cross browsing where the test cases run across various platforms simultaneously. It also helps in creating robust, browser-based regression automation suites and perform tests. 

Moving ahead, let’s understand what is Chrome Driver and how to configure it on your system.

What is Chrome Driver?

WebDriver is an open-source tool for testing of web applications across many browsers. It offers the capabilities for navigating to web pages, user input, JavaScript execution, and many more. ChromeDriver is basically a  standalone server which implements WebDriver’s wire protocol for Chromium. In order to instantiate the object of ChromeDriver, you can simply create the object with the help of below command.

Webdriver driver = New ChromeDriver();

 

The main motto of the ChromeDriver is to launch Google Chrome. Without that, it is not possible to execute Selenium test scripts in Google Chrome browser. This is the main reason why you need ChromeDriver to run test cases on Google Chrome browser. 

Selenium in Chrome - How to Run Selenium in Chrome - Edureka

Now that you know what is Chrome Driver, let’s move further and see how to configure chrome driver on your system.

Chrome Driver Installation

If you wish to know how to configure Chrome Driver on your system in a detailed way, then kindly check out this article on Chrome Driver.

Now let’s dive deeper into the last section of this article and know how to run Selenium script in Chrome browser.

How to Run Selenium in Chrome Browser?

The very step is to configure chrome driver. After that, you need to install Eclipse and add all the Selenium Dependencies to your project. If you wish to know how to configure Selenium and run the first test case, then kindly check this article on Selenium Installation. Once this is done, then you need to write the Selenium Script and instantiate Chrome Driver.

Let’s see how to do that.

Step I: First, you need to set the properties by specifying the type of driver that you are using and the path where you have saved that driver.

Step II: Next, you should instantiate the object of the Chrome Driver as shown in the below code. This will help you to launch the chrome browser

Step III: On using driver.get(), you will be able to navigate through the URL of the particular website.

Step IV: After that, you can locate the elements using locators. If you wish to locate the elements in Selenium, then kindly refer this article on Selenium Locators.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeExample {
public static void main(String[] args) {
//Setting system properties of ChromeDriver
System.setProperty("webdriver.chrome.driver", "C://Selenium-java edureka//chromedriver_win32//chromedriver.exe");
//Creating an object of ChromeDriver
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//Deleting all the cookies
driver.manage().deleteAllCookies();
//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//launching the specified URL
driver.get("https://www.google.com/");
//Locating  the elements using name locator for the text box
driver.findElement(By.name("q")).sendKeys("YouTube");
//name locator for google search button
WebElement searchIcon = driver.findElement(By.name("btnK"));
searchIcon.click();
}
}

When you execute the above code, Chrome Driver will launch Google Chrome browser, navigate through google.com and gives the search result of YouTube. So that’s how it works. If you wish to know in-depth fundamentals of Selenium, then kindly check out this article on Selenium Tutorial.

With this, we come to an end of this article on How to run Selenium in Chrome. I  hope you understood the concepts and it added value to your knowledge.

If you wish to learn Selenium and build a career in the testing domain, then check out our interactive, live-online Selenium Certification Training here, that comes with 24*7 support to guide you throughout your learning period.

Got a question for us? Please mention it in the comments section of How to Run Selenium in Chrome article and we will get back to you.

Comments
0 Comments

Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.