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
Answers:
Try like this
question_element.find_elements_by_xpath("//textarea[position()=1]")
There are two variants that work for search within already found element (not within the whole page):
question_element.find_elements_by_xpath(".//textarea")
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
Try like this
question_element.find_elements_by_xpath("//textarea[position()=1]")
There are two variants that work for search within already found element (not within the whole page):
question_element.find_elements_by_xpath(".//textarea")