0

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('//')
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92

1 Answers1

1

To get to the child of the WebElement you need to set the context to the current element using the dot character i.e. .. 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('.//')
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352