
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Open Chrome in Selenium WebDriver
We can open Chrome browser in Selenium webdriver. We can launch Chrome by instantiating an object of the ChromeDriver class with the help of the below statement.
WebDriver driver = new ChromeDriver();
Next we have to download the chromedriver and configure it to our project by following the below step by step processes −
Navigate to the link − https://www.selenium.dev/downloads/ and below the Browser, there is a Chrome section available. Click on the documentation link just below that.
As per version of the Chrome browser in the system, we have to select the download link. The next page shall be navigated where links to chrome drivers compatible with various operating systems are present.
After selecting the chrome driver as per the system configuration for download, a zip file gets created. We need to extract that and save the chromedriver.exe file at any location.
Let us discuss how to configure chromedriver 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 chromedriver executable path as parameters.
System.setProperty("webdriver.chrome.driver","<chromedriver path>");
Example
Code Implementation
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class ChromeBrw{ public static void main(String[] args) { // creating object of ChromeDriver 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); } }