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
Steps to be followed are same as Firefox. Only the instance will change from Firefox to Chrome
Import webdriver module. The selenium.webdriver module provides support to WebDriver implementations – Firefox, Google Chrome, Internet Explorer and RemoteWebDriver.
from selenium import webdriver
Create a Chrome driver instance
driver = webdriver.Chrome()
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() 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
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") driver.get("http://www.google.com")