Reputation: 81
enter code hereI have two fields by xPath.
1st:
//*[@id="app"]/div/div/div[2]/div/div[2]/div[2]/div[3]/div[1]
2nd:
//*[@id="app"]/div/div/div[2]/div/div[2]/div[2]/div[3]/div[1]/input
I have located and fixed the first div by:
main_field = driver.find_element_by_xpath('//[@id="app"]/div/div/div[2]/div/div[2]/div[2]/div[3]/div[1]')
Is there any way of getting the /input field using the main_field? I mean something like main_field['input']
. I don't want to use the find_element_by_xpath
function again if possible.
Thanks in advance!
Upvotes: 2
Views: 47
Reputation: 193208
As you have located the first field by :
main_field = driver.find_element_by_xpath('//[@id="app"]/div/div/div[2]/div/div[2]/div[2]/div[3]/div[1]')
Now, there is a possibility that the main_field may contain one/multiple child nodes. So to get the specific child <input>
field you can use the reference of the parent node i.e. the main_field but you have to invoke find_element_by_*
again as follows :
main_field.find_element_by_xpath('.//input')
Upvotes: 1