Selenium RC for Python: Tutorial 2__python

Source: Internet
Author: User

To fully test a web system, we need to interact with the system UI and make assertions accordingly.

The most commonly used interactions are implemented through the following methods in selenium.py: Open (URL): Opens a URL in the test frame.  This accepts both relative and absolute URLs. Click (Locator): clicks on a link, button, checkbox or radio button. If The Click Action causes a new page to load (like a link usually does), call Waitforpagetoload. Type (locator, value): Sets The value of an input field, as though you typed it in. Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should is the value of the option selected, not the visible text. Select (selectlocator,optionlocator): Select an option to Drop-down using an option locator. Check (Locator): Check a Toggle-button (checkbox/radio) wait_for_page_to_load (timeout): Waits for a new page to load.

Here are some ways to get information from a page:
Get_title ():  gets The title of the current page. Get_text (Locator): Gets the text of an element. This works for any element, that contains text. This command uses either the Textcontent (mozilla-like browsers) or the innertext (Ie-like browsers) of the element, which is the rendered text shown to the user. Get_value (Locator): Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For Checkbox/radio elements, the value would be ' on ' or ' off ' depending on whether the ' element is ' checked or not. Is_editable (Locator): Determines whether the specified INPUT element is editable, ie hasn ' t been disabled. This method would fail if the specified element isn ' t an INPUT element. Is_element_present (Locator):  verifies that specified element is somewhere on the page. Get_selected_label (selectlocator): Gets option label (visible text) for selected option in the specified SELECT element. Get_selected_value (selectlocator): Gets option value (Value aTtribute) for selected option in the specified SELECT element. Is_something_selected (Selectlocator): Determines whether some option in a Drop-down the menu is selected. Is_checked (Locator): Gets whether a Toggle-button (Checkbox/radio) is checked.  fails if the specified element doesn ' T exist or isn ' t a toggle-button. Get_alert (): Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no Al ERTs. Getting an alert has the same effect as manually clicking OK. If an alert are generated but you don't consume it with Getalert, the next Selenium action     &n Bsp would fail. Under Selenium, JavaScript alerts won't pop up a visible alert dialog.

As written in the previous article, most of the test classes are structurally similar: from. Import ... or import ... class defines the definitions of commonly used variables that refer to the self. Constant in reference to these variables
The definition of the definition test method for SetUp () and teardown, which is the main content of the test run the test using the UnitTest Main method

The code example is as follows:

#! /usr/bin/env python
#coding =utf-8 from
Selenium import selenium
import UnitTest

class Testpageforseleniumremotecontrol (unittest. TestCase):
    Max_wait_in_ms = 60000
    base_url = "http://www.bitmotif.com"
    test_page_url = Base_url + "/ Test-page-for-selenium-remote-control "
    test_page_title = u" TEST page for selenium remote control«bit Motif "
    
    def setUp (self):
        self.verificationerrors = []
        self.selenium = Selenium ("localhost", 4444, "*firefox3 e:/ Program Files/mozilla Firefox/firefox.exe ", self. Base_url)
        Self.selenium.start ()
        
    def teardown (self):
        self.selenium.stop ()
        
    def test_function ( Self):
        passs
      
if __name__ = = ' __main__ ':
    unittest.main ()



Author: Shane
Source: http://bluescorpio.cnblogs.com
This article copyright to the author and blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original connection, otherwise retain the right to pursue legal responsibility.

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.