18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
getting alt attribute value from an img
How would I retrieve the alt text value from an image? I've tried a few things but have come up empty so far.
Here is the HTML code of the object I'm working with:
<img id="t1" border="0" height="18" alt="Client" src="/images/tabs/tabd_Client_0033cc_ffffff.png">
I'm trying to extract the "Client" text from the alt attribute. I tried modifying narayan's solution in this thread (http://sahi.co.in/forums/discussion/comment/16595) with the following:
Which results in "Error: The parameter passed to _getText was not found on the browser"
I've also tried the simpler:
But this returns an empty string.
Any other ideas? I'd prefer to reference the object by the ID since I know that's unique.
Version: Sahi Pro 5.0.9
Browsers: Firefox & IE
Here is the HTML code of the object I'm working with:
<img id="t1" border="0" height="18" alt="Client" src="/images/tabs/tabd_Client_0033cc_ffffff.png">
I'm trying to extract the "Client" text from the alt attribute. I tried modifying narayan's solution in this thread (http://sahi.co.in/forums/discussion/comment/16595) with the following:
var $text;
$text = _getText(_byId("t1"));
_alert($text);
Which results in "Error: The parameter passed to _getText was not found on the browser"
I've also tried the simpler:
var $text;
$text = _getText(_image("t1"));
_alert($text);
But this returns an empty string.
Any other ideas? I'd prefer to reference the object by the ID since I know that's unique.
Version: Sahi Pro 5.0.9
Browsers: Firefox & IE
Best Answer
-
Hi,
Please try using:_image("t1").getAttribute("alt");
Please let me know if it works for you.
Regards.