简体   繁体   中英

How can I get all element's immediate children with css selectors using selenium?

I already tried using the ">" syntax but selenium does not accept it, I know there is a way to get it using Xpath but our entire project is written using CSS selectors.

I am trying to store a list that will contain all immediate children of an element but not their children (descendants), when I use the "*" syntax I get all the element's descendants.

You should specify a tag to start from... if you want "all element's immediate children" , you would simply get all elements, which isn't really what you want.

To get "all immediate children of an element but not their children" for body , use body > * .

Or another example, to get all direct descendants of <div id='question'> , use div#question > * .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM