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

Software Testing

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

How to Run Selenium in Chrome Browser?

Last updated on Sep 10,2024 11.2K 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

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

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.

Find out our Selenium Training in Top Cities/Countries

IndiaOther Cities/Countries
BangaloreUS
HyderabadUK
PuneCanada
ChennaiAustralia
MumbaiSingapore
KolkataEdinburgh

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 - edurekaNow 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.

Related Article: Selenium Interview Questions

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, which 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.

Upcoming Batches For Selenium Course
Course NameDateDetails
Selenium Course

Class Starts on 23rd November,2024

23rd November

SAT&SUN (Weekend Batch)
View Details
Selenium Course

Class Starts on 25th November,2024

25th November

MON-FRI (Weekday Batch)
View Details
Selenium Course

Class Starts on 21st December,2024

21st December

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How to Run Selenium in Chrome Browser?

edureka.co