Selenium: Python client Configuration

Source: Internet
Author: User

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 ()

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.