Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I get an attribute value for a Html control?

How can I get an attribute value for a Html control?

How can I get an attribute value for a Html control?

There is no inbuilt function provided by SilkTest to retrieve or get an attribute value for a given Html control. Therefore a custom function must be created in order to extract the required information from the Html control and there may be a number of ways in which to do this, for example parsing the source code of the given web application.

The example below demonstrates how to retrieve an attribute value for a given Html control:

[-] String GetAttributeValue(window wHtmlWin, string sAttribute)
[ ] //Get a String with the Tag information
[ ] string sDec = WindowTag(wHtmlWin)
[ ]
string sClass = [string]ClassOf(wHtmlWin)
[ ]
[ ] int iBegin = StrPos(sClass,sDec)
[ ]
[ ]
string sAllAttributes = SubStr(sDec,iBegin+Len(sClass)+1)
[ ] //Tag information now held in sAllAttributes
[ ]
[ ] //Find the attributes tag information block
[ ] int iCount = 1
[ ]
string sAttribField = GetField(sAllAttributes,"|",iCount)
[ ]
[-] while(sAttribField != "")
[-]
if(Left(sAttribField,1) == "&")
[ ] break
[ ] iCount++
[ ] sAttribField = GetField(sAllAttributes,"|",iCount)
[ ]
[ ] sAttribField = SubStr(sAttribField,2)
[ ] //Attributes tag information block held in sAttribField
[ ]
[ ] //extract the information for a specific attribute
[ ] iCount = 1
[ ]
string sFAttrib = GetField(sAttribField,";",iCount)
[ ]
[-] while(sFAttrib != "")
[-]
if(Left(sFAttrib,Len(sAttribute)+1) == "{sAttribute}=")
[ ]
break
[ ] iCount++
[ ] sFAttrib = GetField(sAttribField,";",iCount)
[ ] //Attribute information now held in sFAttrib
[ ]
[ ] //format the attribute information so that the attribute value is returned only
[ ] string sFinalAttrib = ""

[-] if(sFAttrib != "")
[ ]
sFinalAttrib = StrTran(sFAttrib,"{sAttribute}=","")
[ ] sFinalAttrib = StrTran(sFinalAttrib,""","")
[ ]
[ ]
//retrun the attribute value
[ ]
return sFinalAttrib

The above function will only retrieve the specified attribute value if the SilkTest recorder is configured to record the said attribute.

Old KB# 23397

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:34
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.