automated-testshp-uftuft14uft-api

Clicking a Webbutton which is the Child of a Webelement using Microsotf UFT


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: HTML code of the specific part

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.


Solution

  • 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).

    To summarise my comments, try this:

    Browser("index:=0").Page("index:=0").WebElement("attribute/data-testid:=.*"&pParent&".*").WebElement("attribute/data-testid:=add:b").Click