I’m creating auto testing for our website, and we have games with hints. For example, a spelling game, and the hints are used to reveal a letter or reduce the number of possible letters, in exchange for coins.
When I’m trying to create a test that will use the hints, they are clicked but the actual action of the hint doesn’t happen.
That’s what I tried to do - use “click” and define the object by the onclick (I also tried the text, the class, the xpath):
When I run the test I get this error in the log, but after a few seconds it passes to the next row in the test and marks it as pass, though nothing happens in the browser in terms of coins reduction or the letter revealed:
Thanks! I pasted the code you wrote in the console and the hint was used (I got a letter revealed in the game).
This is what appears in the console after the hint was clicked - same as it was, only the “undefined” at the bottom was added:
Now you can adjust your Test Object in Katalon to use the button and its id:
I tried the id in the attributes but it didn’t work - after about 30 seconds katalon just marked this line as “passed” and moved to the next one, without anything happening on the hint.
But I tried now the second solution with the xpath - it didn’t work with //button[@id=‘imgGame_revealLetter’], but did work with this: (//button[@id=‘imgGame_revealLetter’]) (that was one of the options in the “Object’s expaths” list).
That means you have two buttons with the same Id imgGame_revealLetter, better approach would be to combine id with another html attribute in that element so you don’t have to use Xpath index which is not recommended practice.
For example you could combine text from the button with id if the button has unique text but it probably doesn’t so in that case combining child with parent element could be unique enough but sometimes it doesn’t.
I know Sometimes it’s better if you are sure this button will stay on index 2 to use index and move on.
OK, I’m pretty sure the button will stay the same (I don’t know where the other button is…).
But just so I’ll know for next time, if I want to combine for example the parent of this id, how would I write it in the xpath? for example here it’s div class=“popover-content”.
Maybe the first button is hidden? You should see it’s code if you write your xpath expression with index .
Xpath expression with provided div and class would be: //div[@class='popover-content']//button[@id=‘imgGame_revealLetter’] but I think you will have again two of them, does the DIV have Id maybe? In many cases where same buttons are used DIV has different Id at least that’s my case.