Python+selenium Primary (3)-webelement interface Common methods

Source: Internet
Author: User

Common interface Methods

Submit #提交表单, especially if there is no submit button, for example, enter in the search box and return to Operation

# Coding=utf-8 from
Selenium import webdriver
import time
driver = Webdriver. Firefox ()

driver.get (' http://www.youdao.com ')
driver.find_element_by_id (' translatecontent '). Send_keys ( ' Hello ')
driver.find_element_by_id (' translatecontent '). Submit ()   #点击回车键
Print (driver.title)
Time.sleep (2)
driver.quit ()

Note: SUBM () and click () can be exchanged, submit () can also be clicked button

Size: return element dimensions

Text: returning element text

Get_attribute (name): Get property value

Is_dispalyed (): Whether the element is visible to the user

# Coding=utf-8 from
Selenium import webdriver
import time
driver = Webdriver. Firefox ()
driver.get (' http://www.baidu.com ')

#获得输入框尺寸
size = driver.find_element_by_id (' kw '). Size
print (size)

#返回百度页面底部备案 result
= Driver.find_element_by_class_name (' Ftcon-wrapper '). Text
Print (Result)

#返回元素是否可见
result1 = driver.find_element_by_id (' kw '). is_displayed ()
print (RESULT1)

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.