Question

I try to find a table row. First, I used Ranorex Spy, and try to use the following rXpath expression:

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

Ranorex Spy finds and highlights this tag successfully. But when I'm trying to find thiselement using Ranorex API, it returns no results. The code is following

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

Can you tell me, where is my mistake or are there any issues with rXpath?

Was it helpful?

Solution

Actually it's not a solution, but a workaround.

The following XPath retrieves a specific entry from . And [1] is an index of a desired element

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

So, the idea is to obtain all elements as a collection, and to use element with an appropriate index.

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];

For my purposes it's enough, though it works 2 times slower if the element was found with direct XPath query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top