0 votes
1 view
in Devops and Agile by (28.1k points)

In Selenium with Python is it possible to get all the children of a WebElement as a list?

1 Answer

0 votes
by (48k points)

Yes, you can do this with 

 find_elements_by_css_selector("*") 

Or

 find_elements_by_xpath(".//*")

please explain your question what you are trying to do.

It is an expensive operation to find direct/indirect children. But have a look over this

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("http://www.intellipaat.com")

header = driver.find_element_by_id("header")

# start from your target element, here for example, "header"

all_children_by_css = header.find_elements_by_css_selector("*")

all_children_by_xpath = header.find_elements_by_xpath(".//*")

print 'len(all_children_by_css): ' + str(len(all_children_by_css))

print 'len(all_children_by_xpath): ' + str(len(all_children_by_xpath))

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...