Ranorex API无法找到Ranorex Spy找到的网络元素

Eug*_*ene 5 .net c# xpath ranorex

我试着找一个表格行.首先,我使用了Ranorex Spy,并尝试使用以下rXpath表达式:

/dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr/.[1]
Run Code Online (Sandbox Code Playgroud)

Ranorex Spy成功找到并突出显示此标记.但是当我尝试使用Ranorex API找到这个元素时,它没有返回任何结果.代码如下

// path is exactly rXpath expression which is used for Ranorex Spy
IList<Ranorex.Core.Element> elements = Host.Local.Find(path);
Run Code Online (Sandbox Code Playgroud)

你能告诉我,我的错误在哪里或rXpath有什么问题吗?

Eug*_*ene 3

实际上这不是一个解决方案,而是一个解决方法。

以下 XPath 从 中检索特定条目。[1] 是所需元素的索引

    /dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr/.[1]
Run Code Online (Sandbox Code Playgroud)

因此,我们的想法是获取所有元素作为集合,并使用具有适当索引的元素。

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];
Run Code Online (Sandbox Code Playgroud)

对于我的目的来说,这已经足够了,尽管如果通过直接 XPath 查询找到元素,它的运行速度会慢 2 倍。