我正在尝试从以下HTML页面找到“x-tree-node”webelement列表。
<div class = "x-tree-root-node"> </div>
<li class = "x-tree-node"> </li>
<ul class = "x-tree-node-ct"> </ul>
<li class = "x-tree-node"> </li> #Starts from here, those elements are the list of 'x-tree-node' I want to find.
<li class = "x-tree-node"> </li> #I want this to be found in my list.
<li class = "x-tree-node"> </li> #I want this to be found in my list.
<li class = "x-tree-node"> </li> #I want this to be found in my list.
我使用的代码是:
public By TopLevelNodeLocator {
get { return By.CssSelector(".x-tree-root-node.x-tree-node.x-tree-node-ct.x-tree-node"); }
}
public IList<IWebElement> AllTopLevelNode {
get { return WebDriver.FindElements(TopLevelNodeLocator); }
}
但IList我得到了一个超时异常,这意味着什么也没找到。
有人可以帮忙吗? 感谢
答案 0 :(得分:1)
By.CssSelector(".x-tree-node")
如果您只想要无序列表的子元素:
By.CssSelector(".x-tree-node-ct .x-tree-node")
或
By.CssSelector(".x-tree-node-ct > .x-tree-node")
或
By.CssSelector("ul .x-tree-node")
或
By.CssSelector("ul > .x-tree-node")
有很多方法可以做到这一点。
TopLevelNodeLocator的属性名称听起来好像是在试图找到根节点,只是fyi。