Selenium-webdriver (Python) (v) Hierarchical positioning

Source: Internet
Author: User

Scene:

If two controls, their long appearance, also called "John", the only difference is one in Beijing, one in Shanghai, then we can go through their cities, districts, streets, to find them.

This problem is often encountered in actual tests: There are many elements on the page that are essentially the same, and you now need to navigate to one of them. Because the attributes are basically equal, there is a bit of trouble locating them, and you need to use hierarchical positioning. The parent element is positioned first, and then the descendant element is positioned through the parent element.

 

To copy this code to Notepad, it will be saved as a level_locate.html file (note that this page needs to be placed in the same directory as our automation script) and the browser opens:

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.