+91 9790664230
kumar.arun211@gmail.com

Test Execution in Chrome using Python Selenium

Blog to learn python and selenium

Test Execution in Chrome using Python Selenium

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 Firefox 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.

driver.get("http://www.google.com");

Final block of code:


from selenium import webdriver
driver = webdriver.Chrome();
driver.get("http://www.google.com");

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>

Example:
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.

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


from selenium import webdriver
driver = webdriver.Chrome(executable_path="/data/Drivers/chromedriver");
driver.get("http://www.google.com");

GitHub Source

 

 

Leave a Reply

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

© 2018 Copyrights. All Rights Reserved. Arunkumar Velusamy