Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

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

1 Answer

0 votes
by (50.2k 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))

Browse Categories

...