Methods of the Webelement class

Source: Internet
Author: User

Methods of the Webelement class, commonly summarized as follows:

Clear () Clears the contents of the input box, such as when logging in

driver.find_element_by_id (' username '). Clear ()

Click (), for example click the login button

driver.find_element_by_id (' Submit '). Click ()

Get_attribute () Gets the value of the element property

zhi=driver.find_element_by_id (' su '). Get_attribute (' type ') to get Baidu home page, "Baidu a bit" the value of the property type, run the result is "submit"

The is_enabled () element is editable and the return value is Boolean

Driver.get (' https://www.baidu.com/')

zhi=driver.find_element_by_id (' su ')

Print zhi.is_enabled ()

Run result is true

Is_displayed () element is visible, returns a Boolean

Is_selected () element is selected, returns a Boolean

Test Baidu--settings--Check whether the radio button on the Settings page is selected

The code is as follows

#coding =utf-8

From Selenium import Webdriver
From selenium.webdriver.common.action_chains import actionchains
Import Time

Driver=webdriver. Firefox ()
Driver.maximize_window ()
driver.implicitly_wait (+)
driver.get (' https://www.baidu.com/')
shezhi=driver.find_element_by_link_text (U ' set ')
actionchains (Driver). Move_to_element (Shezhi). Perform ()
driver.find_element_by_css_selector ('. Setpref '). Click ()
print driver.find_element_by_id (' s1_2 '). is_selected ()
driver.quit ()

"Do not show" in the location, run result: False

send_keys () input content
element.send_keys (U "Xian")
submit () generally used for submission from form

Methods of the Webelement class

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.