最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Nov 23, 2011 at 13:04 Shiran asked Nov 23, 2011 at 12:25 ShiranShiran 1971 gold badge1 silver badge4 bronze badges 3
  • Do you mean that body > * does not give you all direct descendants of the body tag in Selenium? – jro Commented Nov 23, 2011 at 12:32
  • Can you give an example of the CSS selector you are using. In Selenium RC we've got most of our code using CSS selectors with no issue so I'd be surprised if in Selenium2 they've taken a step backwards. – Stephen Commented Nov 23, 2011 at 12:38
  • @jro , I've tried using 'someWebElement.findElement(By.cssSelector(">*"))' The exception thrown is: "invalidElementStateException". – Shiran Commented Nov 23, 2011 at 12:59
Add a comment  | 

1 Answer 1

Reset to default 31

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 > *.

发布评论

评论列表(0)

  1. 暂无评论