18 January 2026:


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.

How to use getAttribute in JUnit

leigh_8385leigh_8385 Members
edited November -1 in Sahi - Open Source
Hi
I am testing a Ext Js site, and the id is dynamic. The only locator is the "for" attribute. And I need to use Sahi in Java mode to build the test framework with TestNG.
I can make it with javascriput like this:
_setValue(_textbox(_label($searchType).getAttribute('For')),$typeName);
but how to do it with Java mode, which API can be used to do this? Thanks

Comments

  • narayannarayan Administrators
    Try

    browser.label(searchType).fetch("For")
  • Hi, Try with fetch("For"), but it returns null
    I try to look into the attributes of Browser element itself. print out browser.label(searchCriteria).fetch(). but it get [object HTMLLabelElement],
    However, fetch("innerHTML") can get the value.
  • narayannarayan Administrators
    Hi Leigh,

    You can do:
    browser.label(searchCriteria).fetch("getAttribute('For')")
    or
    browser.label(searchCriteria).fetch("getAttribute('for')")
    

    This will work on Firefox but not on IE.

    The right way to get the "for" attribute for a label is to get the "htmlFor" property. You can do
    browser.label(searchCriteria).fetch("htmlFor")
    
    This will work for all browsers.

    Regards,
    Narayan
  • It works, Thanks!
This discussion has been closed.