Test Execution in Chrome using Python Selenium

The Blog To Learn Selenium and Test Automation

Test Execution in Chrome using Python Selenium

Page Contents

In this post, we are going to try test execution in Chrome browser and load URL of our choice.

Note: For Firefox Test Execution, Please check here

Method 1

Steps to be followed are same as Firefox. Only the instance will change from Firefox to Chrome

Step 1:

Import webdriver module. The selenium.webdriver module provides support to WebDriver implementations – Firefox, Google Chrome, Internet Explorer and RemoteWebDriver.

from selenium import webdriver

Step 2:

Create a Chrome driver instance

driver = webdriver.Chrome()

Step 3:

Load URL of our choice. WebDriver will wait until the page is loaded completely (the “onload” event has fired) before returning control to next line of script.

When there is AJAX calls on load, WebDriver may not know when page has completely loaded.


Final block of code:

from selenium import webdriver

driver = webdriver.Chrome()

Save this in a python file ‘OpenUrlInChromeBrowser.py’ and execute.

Note: Refer previous article for Firefox to set driver executable path.

To add driver folder path to environment path, use following command in Linux
export PATH=$PATH:<folderpath>

export PATH=$PATH:/data/WorkArea/BrowserDrivers

Method 2

There is another way to start Chrome browser without PATH settings. We have seen this for Firefox Browser

Instead of setting PATH environment variable, executable_path property can be passed while invoking Chrome instance.

driver = webdriver.Chrome(executable_path=”[path to driver location]”);

from selenium import webdriver

driver = webdriver.Chrome(executable_path="/data/Drivers/chromedriver")

GitHub Source


3 Responses

  1. Monika says:

    Step 2 description should be: “Create a Chrome driver instance”.

  2. Sol MacCullagh says:

    Great post.

Leave a Reply

Your email address will not be published. Required fields are marked *