I’m trying to build up a framework for tests using Selenium for a website that has an ADF generated Tree. The tree ends up with the structure of
<table>
<tr>
<td>
<div>
<span>
<a id="AN_ID" title="Expand" onclick="return false" href="#"></a>
</span>
<img>
<img>
<span>SOME_TEXT</ span>
</div>
</td>
</tr>
<tr></tr>
<tr></tr>
</table>
What I’m hoping is to have an XPath function that can use the text to find the id of the anchor, like this:
selenium.getAttribute("xpath=//span[text()='"+text+"']/preceding-sibling::span[1]/child::a@id");
Where text is input into the function when it’s called. The problem arises when the strings aren’t unique. So I tried to add a position into the function, like this:
selenium.getAttribute("xpath=//span[text()='"+text+"']["+occurrence+"]/preceding-sibling::span[1]/child::a@id");
So the the function calls in both the text and the occurrence in the tree of the string. This is working to find the id of the first occurrences, but it fails to find the ids of the second occurrence of a given string.
I’ve also tried to use
[text()= "" and position()= ""]
but this doesn’t work at all.
Each anchor generates a new table that contains all the table rows of the sub level (same structure as above), so that you end up with a new table for each sub level of the tree.
I believe the occurrence should be at the end: