简体   繁体   中英

Get child element using xpath selenium python

We can get a parent of a selenium element using xpath, by

par_element = element.find_element_by_xpath('..')

In a similar fashion, how can we get the child of the element? I tried the following and did not work

child_element = element.find_element_by_xpath('/')
child_element = element.find_element_by_xpath('//')

To get to the child of the WebElement you need to set the context to the current element using the dot character ie . . So effectively your line of code can be either of the following:

child_element = element.find_element_by_xpath('./')

or

child_element = element.find_element_by_xpath('.//')

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