Selenium _ page element locating and operation steps tutorial, selenium operation steps

Source: Internet
Author: User
Tags passthrough

Selenium _ page element locating and operation steps tutorial, selenium operation steps

[Basic steps]

1. Open the browser;

2. Open the webpage;

3: positioning elements and operations;

[Element positioning is the core part of automated testing]

Element name Webdriver API
Id Find_element_by_id ()
Name Find_element_by_name ()
Class name Find_element_by_class_name ()
Tag name Find_element_by_tag_name ()
Link text Find_element_by_link_text ()
Partial link text Find_element_by_partial_link_text ()
Xpath Find_element_by_xpath ()
Css selector Find_element_by_css_selector ()

[Element operation method]

Method Description
Clear Clear Element Content
Send_keys Analog button Input
Click Click
Submit Submit Form

[Code example]

>>> From selenium import webdriver >>> B = webdriver. firefox () >>> B. get ('HTTP: // www.baidui.com ') >>> B. current_url 'HTTP: // www.weitv.com/'> 'baidu' in B. current_urlFalse >>> B. title 'microviewline'> 'baidu' in B. titleFalse >>> B. get ('HTTP: // www.baidu.com ')> B. current_url 'https: // www.baidu.com/'> ele = B. find_element_by_id ('kw ') >>> id (ele) 57685424 >>> type (ele)
 
  
>>> Ele. clear () >>> ele. send_keys ('chongqing Emy ')> B. back ()> B. back ()> B. get ('HTTP: // www.maiziedu.com/') >>> ele = B. find_element_by_link_text ('enterprise passthrough ban') >>> ele. click () >>> B. get ('HTTP: // www.maiziedu.com/') >>> ele = B. find_element_by_link_text ('enterprise passthrough ban') >>> ele. id '0981a127-17c9-46f8-a966-74984b60641a '> ele1 = B. find_element_by_partial_link_text ('passthrough ban') >>>> ele1.id '0981a127-17c9-46f8-a966-74984b60641a '>>> ele_css = B. find_element_by_css_selector ('html body. yaHei. index div. main div. main-container div. main-con-inner div. footer-container div. v5-footer-links.cf (dl. webmap dd ul li A') >>> type (ele_css)
  
   
>>> Ele_css.click () >>> ele = B. find_element_by_css_selector ('input [type = "text"] ') >>> ele. id '454ff57c-de89-417d-b68b-8af5e30636ab '> ele. clear () >>> ele. send_keys ('python ')
  
 
1) B = webdriver. firefox () # Open the browser 2) B. get ('HTTP: // www.baidu.com ') # open a webpage. 3) B. title, B. current_url # determine whether the access is valid 4) ele = find_element_by_id/name () # locate element 5) ele. clear () ele. send_keys (arg) # Clear/input value 6) B. back () # Return 7) ele = B. find_element_by_link_text ('enterprise passthrough class') 8) ele1 = B. find_element_by_partial_link_text ('passthrough ban') 9) ele = B. find_element_by_css_selector ('input [type = "text"] ') # css positioning Element

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.