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.

find an element by attributes value

SaiPradeepSaiPradeep Members
edited August 2013 in Sahi - Open Source
How can we identify the hiddencontrolid < input id = ctl12443 class = "dropdown" hiddencotrolid = "_topic"?something like this.
could please let me know how to identify the object using the hiddencontrolid?
somehow, I achieved through following code:
var $attrElements = [];
<browser>
function getattributeElement(attribute,value)
{
var allElements = document.getElementsByTagName("*");
for(i=0;i<allElements.length;i++)
{
if (allElements.getAttribute(attribute) == value)
{
return allElements;
}
}
}
</browser>
_set($attrElements,getattributeElement("name","password"));
_highlight($attrElements);
var $b = _accessor($attrElements);
_setValue($b,"secret");

this is very flexible tool which can be used according to user requirement,really great enough,I must say

Best Answer

  • edited August 2013 Answer ✓
    Hi,
    You would need a slight change in the 'if' condition in your code.
    if (allElements.getAttribute(attribute) == value)
    {
    return allElements;
    }
    
    with
    if (allElements[i].getAttribute(attribute) == value)
    {
    return allElements[i];
    }
    

    You need to return the element fulfilling the check condition from the whole array. Hence the "".
    So after this change, according to your code,
    the element having attribute "name" with value "password" will be returned.

    Regards.
Sign In or Register to comment.