How to get the URL of an image/icon with Katalon
For a test I'm working on, the status of an item in a table was shown using an icon. It is a yellow triangle for warning and a green checkmark for passed. For my test, I need to know which icon is displayed and act accordingly. In order to check that, I ended up reading the URL of the icon and checking which .PNG file is displayed. Like other elements on the page, the image needs to be defined as an object.
To define the image, I created an object with this reference:
(//td[@id='agreementSigned']/img)[${row}]
It's sort of an odd reference since the icon is in a row within a table. But in essence, the /img
lets us know we are defining and img
object.
To get the text or URL of the object, we need to use the GetAttribute
command:
agreementSigned=WebUI.getAttribute(findTestObject('Business Locations/img-Signed Agreement', [('row') : counter]), 'src')
For the above we have the .getAttribute
which looks at the definition of our img
object. We define the attribute as src
since we want the image source. This will return either:
https://url/check_16.png or https://url/warning16.png
We can then use contains
to see which icon we have:
if (agreementSigned.contains("check_16.png")!=true){
I haven't had to use this before, but getting the answer and putting it together took longer than I would have liked, so hopefully this helps someone out.