I am trying to write a script in UFT, where i need to click on a link (Always the first link in the table), whose title changes dynamically. I tries the following :
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“Class Name”).value = “Link”
Obj_ChkDesc("name").value="Log in"
Browser().page().link(obj_ChkDesc).click
It doesn't work as when the value changes it fails. Could someone tell me what needs to be done to click on the first link whose title changes dynamically?
Thanks in advance.
There are two ways to do it.
First, use Regular Expression
. But it has an assumption that the link
name should follow some rules, say dynamic 10 digits, then you can use [0-9]{10}
as regular expression pattern. To do it, you need to use Spy
to capture this link, then change its property like outerhtml
to regular expression...
Another way (I recommend this one): since you mentioned it is a WebTable
. There is a method called ChildItem
. Let's say the link you want to click will always at Row 1, Col 1
. Then you can write things like this:
'Set Table object
Set TableObj = Browser(...).Page(...).WebTable(...)
'Locate Link
Set LinkObj = TableObj.ChildItem(1,1,"Link",0)
LinkObj.Click
Note that parameter here 1,1,"Link",0
meaning Row,Col,ClassName,Index
. Index
may cause confusion here. Say Row 1 Col 1
has two links, and you want to click second link, then Index
should be 1
.