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

末鹿安然 提交于 2019-12-08 14:35:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!