Find XPath of a Selenium Web Element in Python

Viewed 39

I want to find the XPath of a Selenium Web Element object I already have access to. For example:

driver = webdriver.<browser_of_choice>
parent = driver.find_element(By.ID, "some_ID")
child = parent.find_element(By.CSS_SELECTOR, "some_css_selector")

What I want, is to find the XPath of the child node from within the program. Or some sort of locator that can help me locate the child element directly on the page. So that the following code would work:

new_child = driver.find_element(By.XPATH, "direct_locator_to_child_node")
0 Answers
Related