- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run Selenium WebDriver test cases in Chrome?
We can run Selenium webdriver test cases in Chrome browser. But before working with Chrome browser with Selenium we have to ensure that the Java JDK, any Java IDE like Eclipse and Selenium webdriver are configured in our system. Next we have to download the Chrome browser driver and configure it to our project by following the below step by step process −
Navigate to the link − https://chromedriver.chromium.org/downloads and there links shall be available to the multiple versions of the chromedriver.
As per the available version of the Chrome browser in the system, we have to select the download link. The next page shall be navigated where chrome drivers compatible with various operating systems shall be present.
After downloading the chromedriver as per the system configuration, a zip file gets created. We need to extract that and save the chromedriver.exe file at any location.
Next we can configure the Chrome driver by any of the two ways −
With System Properties in the Environment Variables.
With System Properties in the code.
Let us discuss how to configure chromedriver with System properties within the environment variables −
Navigate to Start and find the System and navigate to it. Then select Advanced System Settings. Next under Advanced Tab click on Environment Variables.
Select Path from the System Variables, then click on Edit. Inside the Edit environment variable pop up click on New.
Now the path of the chromedriver.exe file is added, then click on OK.
Example
Code Implementation
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class LaunchChrome{ public static void main(String[] args) { WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); } }
Let us discuss how to configure chrome driver with System properties within the Selenium code −
Add the System.setProperty method in the code which takes the browser type and the path of the chrome driver executable path as parameters.
System.setProperty("webdriver.chrome.driver","<chrome driver path>");
Example
Code Implementation
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class LaunchChromeBrowser{ public static void main(String[] args) { WebDriver driver = new ChromeDriver(); // to configure the path of the chromedriver.exe System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); } }
- Related Articles
- How to run multiple test cases using TestNG Test Suite in Selenium?
- How do I open Chrome in selenium WebDriver?
- How to run Selenium tests on Chrome Browser using?
- How to programmatically configure Chrome extension through Selenium WebDriver?
- How to mute all sounds in chrome webdriver with selenium?
- How does Selenium Webdriver handle SSL certificate in Chrome?
- Running Selenium WebDriver python bindings in chrome.
- How to use chrome webdriver in Selenium to download files in Python?
- How to open a link in new tab of chrome browser using Selenium WebDriver?
- Using the Selenium WebDriver - Unable to launch chrome browser on Mac
- How to set Google Chrome in WebDriver?
- How to Write Test Cases?
- Test if element is present using Selenium WebDriver?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- How to group test cases in Pytest?
