1. Download Selenium RC and decompress it to drive C.
2. Copy selenium. py to C: \ Python26 \ Lib \ site-packages under C: \ selenium-remote-control-1.0.1 \ selenium-python-client-driver-1.0.1
3. Now the recorded or Handwritten script can interact with the browser.
Selenium now has two versions: selenium-core and Selenium RC.
Selenium-core uses HTML to compile the test script. You can also use Selenium-IDE to record the script. Currently, Selenium-IDE only supports FireFox.
Selenium RC is short for selenium-remote control and is a test class written in a specific language. He supports many languages, such as using my favorite Python.
Switch the directory to C: \ selenium-remote-control-1.0.1 \ selenium-server-1.0.1 in the command line, and then run Java-jar selenium-server.jar.
To use Selenium RC, you must start this server.
Note:
Selenium imitates browser behavior and interacts with the browser using JavaScript. When you run the test class, you will find that Selenium will open a browser and then the browser will execute your operations.
Example 1: Search for hello world on google.com. Note that if you prefer to use .cn, remember to change it to google.com.
Code From selenium import selenium
Import unittest, time, re
Class TestGoogle (unittest. TestCase ):
Def setUp (self ):
Self. verificationErrors = []
Self. selenium = selenium ("localhost", 4444, "* istme", "http://www.google.com/webhp ")
Self. selenium. start ()
Def test_google (self ):
Sel = self. selenium
Sel. open ("http://www.google.com/webhp ")
Sel. type ("q", "hello world ")
Sel. click ("btnG ")
Sel. wait_for_page_to_load ("5000 ")
Self. assertEqual ("hello world-Google Search", sel. get_title ())
# Self. assertEqual (u'hello world-Google \ u641c \ u7d22 ', sel. get_title ())
Print sel. get_title ()
# Def tearDown (self ):
# Self. selenium. stop ()
If _ name _ = "_ main __":
Unittest. main ()