I'm currently working on developing a testautomatisation strategy for a web-client. On this web-client all web-elements have a data-testid which is used to identify the object. Unfortunately in some cases the data-testid is not unique, so clear identification of the object is not possible, I cannot change those data-testids. So I try to write a component which identifies a webelement based on a data-testid and then presses the button which is a child of that element. Unfortunately my code doesn't work, becausse UFT cannot identify my object, I'm unfortunately not able to find the solution by myself. This is how the HTML of the element looks like:
I want to find the Webelement with the data-testid "Orderbeleg_Segmentumbuchung" and then click its child withe the data-testid "add:b".
This is the code I wrote:
Option Explicit
Dim bcName
bcName = "Webbuttonclick_add"
'---------------------------------------------------------------------------------------------
Dim pDoit, pParent, var, debug1
pParent = Parameter("parent")
pDoit = CBool(evalVarAndOffset(Parameter("doit")))
var = "data-testid:= .*" & pParent &".*"
If pDoit = True Then
Browser("index:=0").Page("index:=0").WebElement(var).Click
If Browser("index:=0").Page("index:=0").WebElement(var).exist(1) Then
Browser("index:=0").Page("index:=0").WebElement(var).ChildItem("data-testid:=
add:b").Click
wait 1
End If
End If
SQS_ActionFinish
var is the data-testid of the parent-element.
There are a couple of things I see from reading the question (I didn't actually try to run the code so check to see if I'm right).
data-testid
as a test object property. I don't think this should work since UFT doesn't define this property. Try attribute/data-testid
(further reading).ChildItem
you can nest the WebElement
directly under the var
element. You can use a WebElement
as a container even though UFT doesn't do it by default. In fact ChildItem
is a Table
specific method and not applicable here, if you mean ChildObjects
then the parameter should be a Description
object and not a string with the description inline.var
there's a space before the first .*
, is that intentional?To summarise my comments, try this:
Browser("index:=0").Page("index:=0").WebElement("attribute/data-testid:=.*"&pParent&".*").WebElement("attribute/data-testid:=add:b").Click