1

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('//')

1 Answer 1

2

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('.//')
Sign up to request clarification or add additional context in comments.

2 Comments

I did not think of this, but it did not work.
sorry about that, it worked. I had an extra slash inside the xpath. Updated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.