我试图找到一个表格行。 首先,我使用了 Ranorex Spy,并尝试使用以下 rXpath 表达式:
/dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr/.[1]
Ranorex Spy 成功地找到并突出显示了这个标签。但是当我尝试使用 Ranorex API 查找此元素时,它没有返回任何结果。代码如下
// path is exactly rXpath expression which is used for Ranorex Spy
IList<Ranorex.Core.Element> elements = Host.Local.Find(path);
你能告诉我,我的错误在哪里或者 rXpath 有什么问题吗?
最佳答案
实际上这不是解决方案,而是解决方法。
以下 XPath 从 . [1] 是所需元素的索引
/dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr/.[1]
所以,想法是将所有元素作为一个集合获取,并使用具有适当索引的元素。
String tableRowShortXpath = "/dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr";
IList<Ranorex.WebElement> elements = Ranorex.Host.Local.Find<Ranorex.WebElement>(tableRowShortXpath);
Ranorex.WebElement desiredElement = elements[rowIndex - 1];
就我的目的而言,这就足够了,尽管如果使用直接 XPath 查询找到元素,它的工作速度会慢 2 倍。
关于c# - Ranorex API 找不到 Ranorex Spy 找到的网络元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23471597/