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!