c# - Ranorex API 找不到 Ranorex Spy 找到的网络元素

标签 c# .net xpath ranorex

我试图找到一个表格行。 首先,我使用了 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/

相关文章:

xml - 使用 XPath starts-with 或 contains 函数来搜索 Windows 事件日志

sql - 使用 XPATH/XQUERY 选择具有属性 X 的元素的所有值

C#如何制作泛型方法

c# - SQL 服务器错误 "Procedure expects parameter"

c# - 过滤 ObservableCollection

.net - 如何防止在 ASP.NET/IIS 环境中直接调用 URL?

selenium - 在 IE 中找不到元素,但在 FF 中工作正常

c# - Visual Studio 2012 和 EmguCV 问题

c# - ArrayList 是数组还是列表?

c# - 从 MethodCallExpression 获取投影