Selenium Remote Control: Using the Python Client Driver
First, make sure you've already started the Selenium Server separately in another process. The Selenium Server should remain up and running throughout this process; you shouldn't need to start/stop it each time you use the Client Driver. (Though, of course, if you need to start and stop the server, you certainly can, just by automatically starting it from the command line.)
To use the Python Client Driver, just import selenium.py in your Python script, and create a new selenium_class object. You'll need to give it the hostname and port of the Selenium Server, the browser string to use with "getNewBrowserSession", and the base URL at which we'll start testing. When you're ready to begin, run the "start" method on your selenium_class object; when it's time to close the browser, use the "stop" method.
The selenium_class object is full of handy methods that handle your Selenium Commands. If one of them has an error (or if an "assert" command fails) the method will raise an exception with a handy error message, which you can wrap up in a try/except block if you like.
While we recommend that you use the Python Client Driver together with Python's unittest
unit testing framework, unittest is not required; you can use the Python Client Driver with any program whatsoever to automate tasks in your browser.
Examples: test_default_server.py
, test_ajax_jsf.py