Automated Testing basics-Selenium element positioning, basics-selenium

Source: Internet
Author: User
Tags selenium python

Automated Testing basics-Selenium element positioning, basics-selenium
I. Importance of Selenium element positioning: operations for automated Web Testing: obtains elements on the UI page, operates on the Elements, obtains the actual results, and asserted (whether the returned results are consistent with the expected results ), return the automated test report. This article mainly uses Firebug, an auxiliary plug-in of Firefox browser, to locate elements. Element positioning is crucial in automated testing. If elements on a page cannot be located, all subsequent operations cannot be tested normally, the following describes the eight basic element locating methods provided by Webdriver. Ii. Selenium provides eight positioning methods:

  • Find_element_by_id ()
  • Find_element_by_name ()
  • Find_element_by_class_name ()
  • Find_element_by_tag_name ()
  • Find_element_by_link_text ()
  • Find_element_by_partial_link_text ()
  • Find_element_by_xpath ()
  • Find_element_by_css_selector ()
3. usage of the positioning method: Step 1: Use the baidu search box as an example to open the Baidu webpage; Step 2: locate the search box through the element; Step 3: Enter "selenium Python" in the input box step 4: use the element to locate the Baidu button. Part 5: Click the Baidu button. Step 6: view the search content. 4. How to view elements? Step 1: Open the Firefox browser and open the Baidu homepage; Step 2: The FireBug plug-in has been installed (detailed in the previous article) Step 3: View Elements

Step 4: Use specific methods to locate the specific use of five or eight methods:
  • Locate [find_element_by_id ()

  • Use name to locate [find_element_by_name ()

  • Use class name to locate [find_element_by_class_name ()

  • Use the tag name to locate [find_element_by_tag_name ()

  • Use link text to locate [find_element_by_link_text ()

  • Use partial_link_text to locate (fuzzy match) [find_element_by_partial_link_text ()

  • Use xpath to locate [find_element_by_xpath ()

  • Use css to locate [find_element_by_css_selector ()

Vi. Appendix: Simple Element operation method:
  • Clear element content: clear ()
  • Analog key input: send_keys ()
  • Click: click ()
  • Submit Form: submit ()
Written at the end of the article: these are all compiled into a single word. Originality is not enough. There may be a lot of similar materials, the purpose of this article is to encourage you to develop good habits on the learning road. Therefore, please indicate the source for reprinting. Thank you!

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.