TESTEROPS

A pragmatic approach to QA and OPS

Running Script with Google Chrome

We ran our first script with Firefox. But in day to day scenarios, we are not only concerned with Firefox, but also with other browsers. Since Selenium supports cross-browser testing, so it becomes important that we know how we can use other browsers like Google’s Chrome or IE to support out test.

In this tutorial, we are going to see how we can run the scripts on Chrome browser. Chrome is not one of the browsers that are natively supported by Selenium, however Google’s team works in close connection with Selenium and has created a separate third-party Chromedriver, for supporting Chrome. We are going to test our script using this Chromedriver driver.

However, we need to do a few modifications before we can run Chromedriver and use it to test using Selenium.

  • Download latest version of Chromedriver from this here. As of this date, the current version is v2.16  103.0.5060.53
  • Check for the Chromedriver zip file in /home/Downloads
  • Unzip the Chromedriver file in the Downloads folder. You can do it directly or using command prompt using this command

tar -xvzf  ~/Downloads/chromedriver.tar.bz

  • Copy this unzipped file in the location where test scripts are placed. For me it ~/Documents/SeleniumPy
  • Use either of the following commands to make the chromedriver executable

chmod +x chromedriver

chmod 777 chromedriver

Now we can use the chromedriver in out script. Below is a simple script which will open Google homepage in chrome.


import os
from selenium import webdriver

chrome_path="/home/rahul/Documents/SeleniumPy/chromedriver"

driver=webdriver.Chrome(chrome_path)

driver.maximize_window()

driver.implicitly_wait(30)
driver.get('http://www.google.com')

driver.quit()

This is almost same as the Firefox script, except from the fact that we provided a specific path for the Chromedriver executable, and passed it as a parameter in the call to Chrome driver.

4 thoughts on “Running Script with Google Chrome

  1. Hey man, nice and helpful site for Selenium with Python. It will be more helpful to the visitors if you add a navigation panel or improve the navigation of the page. Every time I want to navigate to the next page, I have scroll to the top and select the topic.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: