Get element inside current element using xpath

Question:

I have multiple questions inside which there are more than 1 options.

After selecting the required question element as question_element

I am unable to get the first text box inside this element. I used

question_element.find_elements_by_xpath("//textarea")

but it gives me list of all the elements with tag textarea in the whole webpage. I tried

question_element.find_elements_by_xpath("/textarea")
question_element.find_elements_by_xpath("./textarea")

but they didn’t give any results. How do I get the first element with tag name textarea inside the question_element

Asked By: raju

||

Answers:

Try like this

question_element.find_elements_by_xpath("//textarea[position()=1]")
Answered By: Santoshsarma

There are two variants that work for search within already found element (not within the whole page):

question_element.find_elements_by_xpath(".//textarea")
Answered By: Igor Khrol