0

i have this element

element = driver.find_element_by_xpath("//*[contains(text(), '/cargas')]")

that search text in html and select one element suppose the element has the xpath

//*[@id="main"]/div[3]/div/div[2]/div[2]/div[11]

is there a way to return div's in this element eg:

element cd.. cd..

//*[@id="main"]/div[3]/div/div[2]

and how i get the full xpath from element

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Matheus Leles
  • 58
  • 1
  • 6

1 Answers1

1

Just like the way in MS DOS you traverse back to the parent directory using cd.., using xpath you can move to the parent element as follows:

element = driver.find_element_by_xpath("//*[contains(text(), '/cargas')]")
parent_element = driver.find_element_by_xpath("//*[contains(text(), '/cargas')]/..")
grand_parent_element = driver.find_element_by_xpath("//*[contains(text(), '/cargas')]/../..")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352