0
我刚开始使用硒c#工作。 我有一个树形视图,它的位置不一致,所以我想扩大它,如果它没有扩大,如果它已经扩大它应该是因为它。类似的崩溃。selenium expand collapse treeview 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工作正常,如果调用适当的操作。 但我想要一个通用操作函数来展开和折叠树,而不考虑它的当前状态。
我试图通过使用文本来获取treeview节点的当前类名称。 这里我想要获得当前类“rtPlus”或“rtMinus” ,但是当我尝试使用标记名称作为范围获得前面的兄弟姐妹时,我得到的类标记范围为“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);
}