How to find an element with respect to its parent element with Selenium and Python

Omar Yacop

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."]

DonnyFlaw

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.

edited at
0

Comments

0 comments
Login to comment

Related

Find element using parent/sibling in python selenium

How to find this element using Selenium (python)

How to find element using type in Selenium and Python

How to find element based on what its value ends with in Selenium?

Selenium - python - how to find the element at a specific position?

Python selenium how to get parent element

How to find element to click button in Python selenium?

How to find element by part of its id name in selenium with python

How to find title="xyz" element with Selenium (Python)

How to find a specific html element with python selenium

How to find an element with respect to the user input using Selenium and Python?

How to find the title of a element in python selenium

How to use the xpath to find a element by the parent? c# selenium

How to find element by its class Selenium?

Is it possible to find a parent element and its child element using Selenium2Library Keywords?

How to find element by color in selenium using python

Python 3 + Selenium: How to find this element by xpath?

How to find element in selenium python

C# : Selenium : How to find an element with respect to the innertext of another element

How to find the last element in python selenium

Find an element with Python Selenium

Find element with python selenium

How to find web element with python with selenium?

How to find element <label for="terms"> Python, selenium

How to get the parent of an element in selenium?

How to get child element based on parent element in python selenium

How to find element using onclick in selenium Python?

How to find this element in Selenium?

Find the parent element of an array by the id of its child