DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Real-Time Face Recognition Using OpenCV, Dlib, and Python
  • From Polling to PubSub: Building an Asynchronous OPC UA Stack in Python
  • Introducing RAI Audit Kit: Evidence-Grade Responsible AI Audits in Python
  • I Was Tired of Flying Blind With AI Agents, So I Built AgentDog

Trending

  • From Polling to PubSub: Building an Asynchronous OPC UA Stack in Python
  • WebSockets, gRPC, and GraphQL in the Core
  • Reading Playwright Traces When Browser Automation Fails
  • The AI Reliability Gap: Why Enterprise AI Is Failing Long Before It Reaches Production
  1. DZone
  2. Coding
  3. Languages
  4. Python - Getting Started With Selenium WebDriver on Ubuntu/Debian

Python - Getting Started With Selenium WebDriver on Ubuntu/Debian

By 
Corey Goldberg user avatar
Corey Goldberg
·
Jul. 02, 12 · Interview
Likes (5)
Comment
Save
Tweet
Share
120.8K Views

Join the DZone community and get the full member experience.

Join For Free

This is a quick introduction to Selenium WebDriver in Python on Ubuntu/Debian systems.

WebDriver (part of Selenium 2) is a library for automating browsers, and can be used from a variety of language bindings. It allows you to programmatically drive a browser and interact with web elements. It is most often used for test automation, but can be adapted to a variety of web scraping or automation tasks.

To use the WebDriver API in Python, you must first install the Selenium Python bindings. This will give you access to your browser from Python code. The easiest way to install the bindings is via pip.

On Ubuntu/Debian systems, this will install pip (and dependencies) and then install the Selenium Python bindings from PyPI:

$ sudo apt-get install python-pip
$ sudo pip install selenium

After the installation, the following code should work:

#!/usr/bin/env python

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')

This should open a Firefox browser sessions and navigate to http://www.ubuntu.com/

Here is a simple functional test in Python, using Selenium WebDriver and the unittest framework:

#!/usr/bin/env python

import unittest
from selenium import webdriver


class TestUbuntuHomepage(unittest.TestCase):
    
    def setUp(self):
        self.browser = webdriver.Firefox()
        
    def testTitle(self):
        self.browser.get('http://www.ubuntu.com/')
        self.assertIn('Ubuntu', self.browser.title)
        
    def tearDown(self):
        self.browser.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)

 Output:

testTitle (__main__.TestUbuntuHomepage) ... ok

----------------------------------------------------------------------
Ran 1 test in 5.931s

OK
Python (language)

Published at DZone with permission of Corey Goldberg. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Real-Time Face Recognition Using OpenCV, Dlib, and Python
  • From Polling to PubSub: Building an Asynchronous OPC UA Stack in Python
  • Introducing RAI Audit Kit: Evidence-Grade Responsible AI Audits in Python
  • I Was Tired of Flying Blind With AI Agents, So I Built AgentDog

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook