selenium webdriver
Selenium is a web automation framework that can be used to automate website testing. Because Selenium starts a webbrowser, it can do any task you would normally do on the web.
Related course
Practice Python with interactive exercises
Web Driver To start a web browser, the Selenium module needs a web driver. Supported browsers are:
- Chrome
- Firefox
- Internet Explorer
- Safari
- Opera
- PhantomJS (invisible)
To start a browser, you will need to corresponding driver. The driver "ChromeDriver" is needed to start Chrome, "FirefoxDriver" for Firefox.
All drivers can be downloaded from: https://docs.seleniumhq.org/download/
Example code Python will start and control the chromium browser using the code below:
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://python.org')
You can change the browser using:
# Firefox
driver = webdriver.Firefox()
# Google Chrome
driver = webdriver.Chrome()
# iPhone
driver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')
# Android
driver = webdriver.Remote(browser_name="android", command_executor='http://127.0.0.1:8080/hub')