How to invoke the Chrome browser in Selenium with python?

We can invoke any browsers with the help of the webdriver package. From this package we get access to numerous classes. Next we have to import the selenium.webdriver package. Then we shall be exposed to all the browsers belonging to that package.

For invoking chrome browser, we have to select the Chrome class. Then create the driver object of that class. This is the most important and mandatory step for browser invocation.

Every chrome browser gives an executable file. Through Selenium we need to invoke this executable file which is responsible for invoking the actual chrome browser.

Next we need to download the chrome driver version as per our browser version. The path of the chromedriver.exe file needs to be added in the executable file. Then we need to use the get () method to launch our application in that particular browser.


Code Implementation

from selenium import webdriver
#browser exposes an executable file
#Through Selenium test we will invoke the executable file which will then #invoke actual browser
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
# to maximize the browser window
#get method to launch the URL
#to refresh the browser
#to close the browser

Updated on: 29-Jul-2020

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started