问题
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.
回答1:
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 > *
.
来源:https://stackoverflow.com/questions/8242169/how-can-i-get-all-elements-immediate-children-with-css-selectors-using-selenium