RanorexSpy XPath not indexing elements in the right DOM structure order

492 Views Asked by At

When searching for elements with the same class, RanorexSpy finds all the elements, but fails to index them in the order of the dom structure. Is there any function or another way to search for the elements or is this a bug?

I have setup a simple website for an example.

<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <div class="class_sample">1</div>
    <div class="class_sample">2</div>
    <div class="class_sample">3</div>
    <div class="class_sample">4</div>
    <div>
        <div>
            <div class="class_sample">5</div>
        </div>
    </div>
    <div class="class_sample">6</div>
    <div class="class_sample">7</div>
    <div class="class_sample">8</div>
    <div class="class_sample">9</div>
    <div class="class_sample">10</div>
</body>
</html>

As you can see I have 10 divs with the same class name and the 5th element is nested inside 2 divs.

When searching for the element in xpath: /dom[@caption='Document']/body//div[@class='class_sample'], I get all the divs with the class, but Ranorex failes to index them in order of the dom structure.

The first 4 divs are indexed in order, but as soon as I try to find the element with the index of '5' (which is nested). It skips to the 6th div. The 5th element has the index of 10.

Here are the links to pictures.

Wrong indexing:

Wrong indexing

Wrong indexing

1

There are 1 best solutions below

3
Martin Honnen On

Try /dom[@caption='Document']/body/descendant::div[@class='class_sample'][5] or /dom[@caption='Document']/body/descendant::div[@class='class_sample'][10].

https://xqueryfiddle.liberty-development.net/nc4P6yh has an example for descendant::div[@class='class_sample'][5] selecting <div class="class_sample">5</div>, https://xqueryfiddle.liberty-development.net/nc4P6yh/1 has an example for descendant::div[@class='class_sample'][10] selecting <div class="class_sample">10</div>.

(//div[@class='class_sample'])[5] selects <div class="class_sample">5</div> at https://xqueryfiddle.liberty-development.net/nc4P6yh/2 and (//div[@class='class_sample'])[10] selects <div class="class_sample">10</div> at https://xqueryfiddle.liberty-development.net/nc4P6yh/3.

On the other hand, //div[@class='class_sample'][5] right selects <div class="class_sample">6</div> at https://xqueryfiddle.liberty-development.net/nc4P6yh/4 as //div is short for /desendant-or-self::node()/div so //div[@class='class_sample'][5] is /desendant-or-self::node()/div[@class='class_sample'][5].