Highlighted
Regular Contributor.. zux Regular Contributor..
Regular Contributor..
321 views

UFT can't retrieve parent WebElement of a specific existing WebElement

Hi,
I would like to know how to fetch a parent of a WebElement and click on it?
I attached my code. I did try parentElement but then Click does not work.

<code>

Set rowDescriptor = Description.Create
rowDescriptor("micclass").value = "WebElement"
rowDescriptor("html tag").value = "TR"
Set foundRows=Browser("Rothschild App").Page("Rothschild App").WebTable("gposTable").ChildObjects(rowDescriptor)


Set colDescriptor = Description.Create
colDescriptor("micclass").value = "WebElement"
colDescriptor("html tag").value = "SPAN"


Dim found, i, obj
i=0
found=false
While i < foundRows.Count - 1 And found = false
     Set foundSpans=foundRows(i).ChildObjects(colDescriptor)
     For j = 0 to foundSpans.Count - 1
           print foundSpans(j).GetROProperty("innertext") 

           If Trim(foundSpans(j).GetROProperty("innertext")) = DataTable("GPOSCreate_Name", dtLocalSheet) Then
                 found = true
                 obj = foundSpans(j).Object.parentElement
                 Exit For
          End If
      Next
       i=i+1
Wend
If found = true Then
        Reporter.ReportEvent micPass, "C00102 - chk 2 - Passed", "Found newly created item"
        'this does not work because parentElement is a DOM element and not a WebElement
       obj.Click
        ........
</code>


if you can help me it would be great.

Best regards,
Andrea

Tags (3)
0 Likes
1 Reply
Manuel Solano Respected Contributor.
Respected Contributor.

Re: UFT can't retrieve parent WebElement of a specific existing WebElement

Hi Zux,

Hope you are doing great!

My name is Manuel Solano from MicroFocus UFT support.

Could you please try with this script and let us know the results:

sInnerText = "" 'Enter the WebElement's Innertext property_value here
 
Set baseObj = Browser("creationtime:=1").Page("micclass:=Page")
 
Set oDesc = Description.Create
oDesc("micclass").value = "WebTable"
 
Set oTableColl = baseObj.ChildObjects(oDesc)
 
'counter = 0
 
For i = 0 to oTableColl.Count
          tblRows = oTableColl(i).GetROProperty("rows")
          tblCols = oTableColl(i).GetROProperty("cols")
 
          If (tblRows > 0) And (tblCols > 0) Then
                   For nRow = 1 to tblRows
                             For nCol = 1 to tblCols
                                      sData = oTableColl(i).GetCellData(nRow, nCol)
                                      If (InStr(sData, sInnerText)) Then
                                                Set pTable = oTableColl(i) 'You might need to set a counter (See below)
                                                pTable.Highlight
                                      End If
                             Next
                   Next
          End If
Next
 
 
'Counter: If QTP sees 2 WebTables, then the 2nd WebTable is the immediate parent. Thus,
'the script should exit when the counter reaches a value of 2. 

That code worked on an application which uses AJAX as well

Regards,

0 Likes
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.