Selenium + Python automation Test unittest Framework Learning (iii) WEBDRIVER element operations (ii)

Source: Internet
Author: User

The previous article is the positioning of elements, then the purpose of positioning elements is to manipulate elements, such as writing text, click Buttons, drag and so on operations

(1) Simple element operation

Simple element manipulation

find_element_by_id ("kw").  Clear ()                         #文本框清空 find_element_by_id ("kw"). Send_keys ("selenium")           #文本框输入find_element_by_id ("button "). Click ()                     #点击按钮操作

(2) Common operation of Webelement interface:

Webelement class content: Get element attributes, location, visibility, element dimensions, elements, etc.

 fromSelenium.webdriver.remoteImportwebelementfind_element_by_id ("kw").Get_attribute("type") #获取元素的属性值find_element_by_id ("Submit"). Submit () #提交表单flag= find_element_by_id ("kw"). is_displayed () #获取元素是否可见 with a value of true or Falsesize= find_element_by_id ("kw").size#获取元素的大小

(3) Mouse operation: Double-click, right mouse button, mouse movement, drag to the elements of the fine operation

Actionchains (Driver): action to store the mouse

Perform (): Execution of the specified mouse action

From selenium.webdriver.common.action_chains Import actionchainsright = driver.find_element_by_id ("id") actionchains (driver). Context_clcik ("right"). Perform ()             #鼠标右键left = driver.find_element_by_id ("id") Actionchains (driver).  Click_and_hold("left"). Perform ()             #鼠标左键double = driver.find_element_by_id ("id") Actionchains (driver).  Double_clcik("Double"). Perform ()             #鼠标双击move = driver.find_element_by_id ("id") Actionchains (driver).  Move_to_element("move"). Perform ()            #鼠标移动到某个元素上start = driver.find_element_by_id ("id1") end = Driver.find_ element_by_id ("Id2") actionchains (Driver). Drag_and_drop (Start,end). Perform ()           #鼠标拖动某个元素从start位置到end的位置

(4) Keyboard operation

The operation of the keyboard is based on the Send_keys () method

 fromSelenium.webdriver.common.KeysImportkeysdriver.find_element_by_id ("kw"). Send_keys (KEY.  Back_space) #删除键driver. find_element_by_id ("kw"). Send_keys (KEY.  ENTER) #回车键driver. find_element_by_id ("kw"). Send_keys (KEY.  SPACE) #空格键driver. find_element_by_id ("kw"). Send_keys (KEY.  TAB) #制表符driver. find_element_by_id ("kw"). Send_keys (KEY.  ESCAPE) #退出键driver. find_element_by_id ("kw"). Send_keys (KEY. CONTROL,'a') #全选driver. find_element_by_id ("kw"). Send_keys (KEY. CONTROL,'C') #复制driver. find_element_by_id ("kw"). Send_keys (KEY. CONTROL,'v') #粘贴driver. find_element_by_id ("kw"). Send_keys (KEY. CONTROL,'x') cut

Selenium + Python automation Test unittest Framework Learning (iii) WEBDRIVER element operations (ii)

Related Article

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.