Common methods of Webelement interface __web

Source: Internet
Author: User
From selenium import webdriver

#webElement接口常用方法
#clear (): Clears the contents of the text box
#send_ Keys (): Analog keyboard input
#click (): Click the button, can be clicked on the element;
#可以是任何可以点击的文字, Picture link, radio box, check box, Drop-down box
#submit (): Submit the form, especially if there is no submit button
#size: Get element size
#text: Get element text
#get_attribute (name): Get property value

driver=webdriver. Ie ()
driver.get ("https://www.baidu.com")
#百度输入框中输入test
driver.find_element_by_id (' kw '). Send_ The Keys ("test") Sleep
(4)
#清除test
driver.find_element_by_id (' kw '). Clear () Sleep
(4)
driver.find_element_by_id (' kw '). Send_keys ("python")
#submit相当于回车
driver.find_element_by_id (' kw '). Submit () Sleep
(4)

#获取百度搜索框id的属性值
attribute=driver.find_element_by_id ("kw"). Get_attribute ("id")
print ("Attibute:", attribute)

#获取百度输入框的尺寸
size=driver.find_element_by_id ("kw"). Size
Print ( "Size:", size)

#获取百度首页百度按钮的文本信息
text=driver.find_element_by_id ("su"). Text
print ("The textual message of the Baidu button is:", Text) sleep
(5)
driver.quit ()

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.