【发布时间】:2017-11-24 10:39:44
【问题描述】:
我刚开始使用 selenium c#。 我有一个树视图,它的位置不一致,所以如果它没有展开,我想展开它,如果它已经展开,它应该是原样。崩溃也类似。
这是树展开的时候
<div class="rtTop">
<span class="rtSp"></span>
<span class="rtMinus"></span>
<span class="rtIn">Roles</span>
</div>
这就是它崩溃的时候
<div class="rtTop">
<span class="rtSp"></span>
<span class="rtPlus"></span>
<span class="rtIn">Roles</span>
</div>
我目前正在使用
public static string treeviewExpand( string treeviewExpandButton)
{
treeviewExpandButton = "//span[text()='" + treeviewExpandButton + "']/preceding-sibling::span[@class='rtPlus']";
return treeviewExpandButton;
}
public static string treeviewCollapse(string treeviewCollapseButton)
{
treeviewCollapseButton = "//span[text()='" + treeviewCollapseButton + "']/preceding-sibling::span[@class='rtMinus']";
return treeviewCollapseButton;
}
如果调用了适当的操作,上述 xpath 可以正常工作。 但我想要一个通用的动作函数来扩展和折叠树,而不管它的当前状态。
我试图通过使用文本来获取树视图节点的当前类名。 在这里,我正在尝试获取当前类“rtPlus”或“rtMinus” 但是当我尝试使用标签名称作为 span 来获取前面的同级时,我得到的是带有类“rtsp”而不是类“rtPlus”或“rtMinus”的标签跨度 即使检查显示其先前的兄弟跨度具有类“rtPlus”或“rtMinus”
我正在使用
public static string treeviewExpandCollapse(string treetext)
{
treetext= "//span[text()='" + treetext+ "']";
IWebElement element;
element = driver.FindElement(treetext).FindElement(By.XPath("./preceding-sibling::span"));
string calsss = element.GetAttribute("class");
Thread.Sleep(2000);
}
【问题讨论】:
标签: c# selenium telerik treeview telerik-mvc