Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ranorex API can't find a web element which Ranorex Spy finds

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='[email protected]']/../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?

like image 241
Eugene Avatar asked Oct 21 '22 09:10

Eugene


1 Answers

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='[email protected]']/../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='[email protected]']/../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.

like image 62
Eugene Avatar answered Oct 23 '22 11:10

Eugene