python logo

selenium webdriver

Python hosting: Host, run, and code Python in the cloud!

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.

If you are new to selenium and browser automation, I recommend the course below.

Related course
Browser Automation with Python Selenium

Web Driver

To start a web browser, the Selenium module needs a web driver. Python interacts with the selenium web driver and the web driver interacts with the browser.

Supported browsers are:

  • Chrome
  • Firefox
  • Internet Explorer
  • Safari
  • Opera
  • PhantomJS (invisible)

To start a browser, you will need to corresponding web driver. The driver “ChromeDriver” is needed to start Chrome, “FirefoxDriver” for Firefox.

All drivers can be downloaded from:

Example code
Python will start and control the chromium browser using the code below:

from selenium import webdriver
import time

options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)

You can change the browser by creating a different instance:

# Firefox
driver = webdriver.Firefox()

# Google Chrome
driver = webdriver.Chrome()

# iPhone
driver = webdriver.Remote(browser_name="iphone", command_executor='')

# Android
driver = webdriver.Remote(browser_name="android", command_executor='')

The first two lines in the above code will open the browser on the same computer, the others lines open the browser remotely: on a phone.

Then open a webpage using the get() method:


Download Selenium Examples


Leave a Reply: