I'm using selenium with java and I'm trying to test the search scenario. After I perform the search the html elements which do not suite the search keyword are hidden with hidden attribute (see the example below, the first element does not match the search criteria and the second does):
<ion-item-sliding class="item-wrapper" hidden="">
<button class="item item-block item-md" ion-item="">
<p>I am hidden</p>
</button>
</ion-item-sliding>
<ion-item-sliding class="item-wrapper">
<button class="item item-block item-md" ion-item="">
<p>I am not</p>
</button>
</ion-item-sliding>
My goal is to find the text in the visible element (the second one in the example). When I use the simple selector
//button[@class='item item-block item-md']
the hidden element gets found, so I'm using the selector like this
//ion-item-sliding[@class='item-wrapper' and not @type='hidden']//button[@class='item item-block item-md']...
but no luck. Please advice with any ideas/documentation about the selector.
What you need here is to utilize the getAttribute function. What this call does is that it returns an attribute value if its set or null otherwise.
You can use FindElements passing your selector, and iterate over the found elements and only return the one where
getAttribute("hidden") != null
Hope this helps.