Selenium – Open Chrome Browser

Python Selenium – Open Chrome

In this tutorial, you shall learn how to open Google Chrome browser, using Selenium, in Python language.

We shall use webdriver_manager for creating a driver object for the Chrome. If you do not have webdriver_manager installed, open a terminal or command prompt, and run the following pip command.

pip install webdriver-manager
Copy

Steps to open Chrome browser using Selenium Python

Step 1

The first step in creating a Chrome driver instance is to import ChromeDriverManager class from the webdriver_manager.chrome module.

ChromeDriverManager class instance identifies the required webdriver package for the version of Chrome installed in your system.

The webdriver package is fetched dynamically from the predefined online repository, based on your Operating System and the version of Chrome present in your system.

Step 2

Import Service class from chrome.service module present in selenium.webdriver. This shall be used for the service parameter of webdriver.Chrome().

Step 3

Create a Chrome webdriver instance using webdriver.Chrome class.

You do not have to remember these steps. Just copy the first six lines of code from the following example, and everything should be fine to create a Chrome webdriver instance and open a Chrome browser window.

Example

In the following example, we followed the above said steps to create a Chrome webdriver instance, and open a Chrome browser window.

Python Program

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService

# Initialize Chrome driver instance
driver = webdriver.Chrome(service=ChromeService(executable_path=ChromeDriverManager().install()))

# Navigate to the url
driver.get('https://pythonexamples.org/tmp/selenium/index.html')

# Close the driver
driver.quit()
Copy

Summary

In this Python Selenium Tutorial, we have seen how to create a Chrome webdriver instance and open a Chrome browser window.

Related Tutorials

Quiz on Selenium

Q1. What is Selenium Python used for?

Not answered

Q2. What is the method used to interact with web elements in Selenium Python?

Not answered

Q3. What is the method used to navigate back to the previous page in Selenium Python?

Not answered

Q4. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q5. What is the method used to take a screenshot in Selenium Python?

Not answered
Code copied to clipboard successfully 👍