Easy Automation---selenium-webdriver (python) (vi)

Source: Internet
Author: User
Tags tag name xpath

http://www.testclass.net/ Test Tutorial Network, professional Selenium learning website.

Knowledge points in this section:

Action object:

    • · Click on Object
    • · Send_keys analog key input on the object
    • · Clear clears the contents of the object, if possible

Webelement Other common methods:

    • · Text gets the literal of the element
    • · Submit Form
    • · Get_attribute Getting property values

======================================

Manipulating Test objects

In front of a lot of knowledge are positioning elements, positioning is only the first step, after the positioning of the primitive to operate.

Mouse click or keyboard input, it depends on what we are positioning is the button also input box.

In general, there are several ways to compare commonly used operands in Webdriver

· Click on Object

· Send_keys analog key input on the object

· Clear clears the contents of the object, if possible

In our first example of this series we used the Click and Send_skys, don't turn back and look, I'll post the code:

#coding = Utf-8From seleniumImport Webdriverbrowser = Webdriver. Firefox () browser.get ( "http://www.baidu.com ") browser.find_element_by_id (" kw "). Clear () Browser.find_ element_by_id ( "kw"). Send_keys ( "selenium" Span style= "COLOR: #000000" >) browser.find_element_by_id (su "). Click () Browser.quit ()               

Send_keys ("XX") is used to enter content in an input box.

Click () to tap a button.

Clear () for clearing the contents of the input box, such as the Baidu input box by default there is a "Please enter the keyword" information, and then for example, our landing box is usually the default "account" "password" such as the default information. Clear can help us clear this information.

Webelement Other common methods:

· Text gets the literal of the element

· Submit Form

· Get_attribute Getting property values

Text

The text information used to get the element

Below the Baidu home page at the bottom of the declaration print output

#Coding=utf-8From seleniumimport Webdriverimport< Span style= "COLOR: #000000" > timedriver = Webdriver. Firefox () driver.get ( "http://www.baidu.com ") time.sleep (2#id = text information for CP elements data=driver.find_element_by_id ( "cp" print data # print information time.sleep (3 

Output:

>>>

Submit

Submit Form

We changed the "Baidu" operation from Click to submit:

#Coding=utf-8From seleniumImportWebdriverImport timedriver = Webdriver. Firefox () driver.get ( "http://www.baidu.com ") driver.find_element_by_id (" kw" selenium" ) time.sleep (2" # operation via submit () driver.find_element_by _id ( "su" ). Submit () Time.sleep (3     

Here with the click of the effect of submit, I have not thought for a moment can only use the click of the scene with submit. What is the difference between them, know the classmate please leave a message to tell me.

Get_attribute

Gets the property value.

The usage of this function has already appeared before, it is used when locating a set of elements, but we do not have much explanation.

General usage:

select = Driver.find_element_by_tag_name ("select") alloptions = Select.find_elements_by_tag_name ( "option")in"" + option.get_attribute ("value") Option.click () 

Specific application reference:

Positioning a group of elements: http://www.cnblogs.com/fnng/p/3190966.html

Summary:

Learn here we have been holding a lot of knowledge, simple operation of the browser, positioning elements, manipulating elements and printing some information. In fact, most of the study in front of us used the method of webelement.

Methods of Webelement:

In general, all interesting operations that interact with the page are done through webelement.

Classselenium.webdriver.remote.webelement.WebElement (parent, id_)

This class represents an HTML page element

Ld:#ID of the current elementTag_name#Gets the attribute of the element tag nameText#Gets the text of the element.Click ()#Click (tap) an elementSubmit ()#Submit FormClear ()#Clears the text of a text INPUT elementGet_attribute (name)#Get property valueS_selected (self)#Whether the element is selectedWhether the ElementIsSelected.is_enabled ()#Whether the element is enabledfind_element_by_id (id_) find_elements_by_id (id_)#Find the ID of an elementFind_element_by_name (name) find_elements_by_name (name)#Find the name of an elementFind_element_by_link_text (Link_text) find_elements_by_link_text (Link_text)#Find link text for an elementFind_element_by_partial_link_text (Link_text) find_elements_by_partial_link_text (Link_text)#Find part of a link to an element of textFind_element_by_tag_name (name) find_elements_by_tag_name (name)#Find the label name of an elementFind_element_by_xpath (XPath)#Find XPath for an element Find_elements_by_xpath (XPath) #  find child elements within an element Xpath Find_element_by_class_name (name) # Find the class name of an element  find_elements_by_ Class_name (name) # Find the class name of an element  Find_element_by_css_selector (css_selector) # Find_elements_by_css_selector (css_selector) # Find and return a list of CSS selectors for multiple elements  send _keys (*value) # analog input elements  

--------------------------

Learn more about selenium content:

Functional Test Automation Rollup

Easy Automation---selenium-webdriver (python) (vi)

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.