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
- Check for the Chromedriver zip file in
- 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
- 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.
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.
Thanks for the feedback. Will try to see if that’s possible.
I have shared the code that i have written.