IBM Support

Selecting an HTML link that has dynamic text using Rational Robot

Question & Answer


Question

How can you create a resilient IBM® Rational® Robot GUI script that will make a selection on an HTML link, when the text within the link is dynamic?

Cause

Selecting an HTML Robot link that has dynamic text poses challenges as parts of the recognition properties of the object being tested are changing.

Answer

If you know where on the page the link text is the following script will help you get the recognition strings for all links on the page. If you know which link you want to select then the capture recognition string can be added to an html click statement to select the link. The script below demonstrates this against the "htmltryit" sample application that comes with Rational products.
Note: If you cut and paste this script into Robot please make sure that line overruns are corrected within the script before running it.

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.



'$Include "sqautil.sbh"

Sub Main
dim result As Integer
dim pgname() as string
dim count as integer
dim length as integer
dim location as integer
dim retrieve as integer
dim test as string
dim check(100) as string 'Assumes 100 html links maximum.  Increase if more than 100.
dim num as integer
dim x as integer

StartBrowser "C:\Program Files\Rational\Rational Test\Sample Applications\Html tryit\HTMLTryIt.htm", ""

Window SetContext, "Caption=HTML TryIt - Microsoft Internet Explorer", ""
Window WMaximize, "", ""
Browser SetFrame,"Type=HTMLFrame;HTMLId=top",""
Browser NewPage,"HTMLTitle=topFrame",""
HTMLImage Click, "Type=HTMLImage;Index=4", "Coords=32,22"

result = sqagetchildren("Type=HTMLFrame;HTMLId=bottom;\;Type=HTMLDocument;HTMLTitle=IMage Map Link", pgname)

num = 0

for count = 0 to ubound(pgname) 'Scroll through all items captured by sqagetchildren

length = 0
location = 0
retrieve = 0

test = "Type=HTMLLink" 'This is what I am looking for in the string

length = len(pgname(count)) 'Gets the total length of each string

location = Instr(pgname(count), test) 'Returns the position of the first instance of Type=HTMLLINK

if location <> 0 then 'If it finds Type=HTMLLink

retrieve = (length-location) + 1

check(num) = right(pgname(count), retrieve) 'Take the syntax found and everything to the right

'sqaconsolewrite (check(num))

num = num + 1 'Count the number of times a link is found

end if

next count

for x = 0 to ubound(check)

if (num-1) = x then

Window SetContext, "Caption=HTML TryIt - Microsoft Internet Explorer", ""
Browser SetFrame,"Type=HTMLFrame;HTMLId=bottom",""
Browser NewPage,"HTMLTitle=Image Map Link",""

HTMLLink Click, check(x), "" 'Make the link selection (this will be the last link captured)

end if

next x

End Sub



[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Playback","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003.06.00;2003.06.10;2003.06.12;2003.06.13;2003.06.14;2003.06.15;2003.06.16;7.0;7.0.0.1;7.0.0.2;7.0.1;7.0.1.1;7.0.0.3;7.0.1.2;7.0.0.4;7.0.1.3;7.0.2","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

21004

Document Information

Modified date:
16 June 2018

UID

swg21133803