简体   繁体   中英

How to find an element that satisfies a condition in the following tree?

Using Python and Selenium how do I find an element that satisfies a condition in the following tree?

(S, A ~ H is Class)

S
├── A
├── B
├── C
│   └── D
├── E
│   └── F
├── G
└── H

When D is present, we want to find the element of F.

If s is the webelement root and we want to check if a class exists within that element we do the following.

elem=s.find_element_by_xpath("//[class='c']/[class='d']")
if elem:
   s.find_element_by_xpath("//[class='e']/[class='f']")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM