Ranorex API不能找到Ranorex Spy找到的web元素

本文关键字:Ranorex web 元素 Spy API 不能 | 更新日期: 2023-09-27 18:01:38

我试图找到一个表行。首先,我使用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有什么问题吗?

Ranorex API不能找到Ranorex Spy找到的web元素

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

下面的XPath从。[1]是所需元素

的索引
    /dom[@domain='127.0.0.1']//table//td[@innertext='john.doe@acme.com']/../following-sibling::tr/.[1]

因此,其思想是将所有元素作为一个集合获取,并使用具有适当索引的element。

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倍。