I am trying to scrape a website, but I need to search for an element whose parent is like this:
//div[@title="parent"]
People are talking about getting an element from its child. Is there a way to reverse it and find the child from its parent?
I want the /span
with @title = "child"
whose parent is //div[@title = "Search results."]
You can try to use
//div[parent::div[@title="parent"]]
or simply
//div[@title="parent"]/div
In Python code you can also use
parent = driver.find_element(By.XPATH, '//div[@title="parent"]')
child = parent.find_element(By.XPATH, './div')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments