Answers for "python selenium get children"

2

python selenium get child element

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.stackoverflow.com")

#Here you get the parent element
header = driver.find_element_by_id("header")

#Here you can get all the child elements by css:
all_children_by_css = header.find_elements_by_css_selector("*")

#Or here you can get all the child elements by xpath:
all_children_by_xpath = header.find_elements_by_xpath(".//*")

#And if you just want one element you can take it by index:
all_children_by_xpath[0] #for first item
all_children_by_xpath[1] #for the 2
Posted by: Guest on July-09-2021
0

selenium get all child elements python

el = driver.find_element_by_name('a')

// Two ways to get all children elements.
// By css selector:
childrend_by_css = el.find_elements_by_css_selector("*")
// By xpath:
childrend_by_xpath = el.find_elements_by_xpath(".//*")
Posted by: Guest on July-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language