cancel
Showing results for 
Search instead for 
Did you mean: 

struggling to retrieve the first value found in a web table based on expected text

SOLVED
Highlighted
Frequent Contributor

struggling to retrieve the first value found in a web table based on expected text

Hello,

i'm trying to verify value in webtable.it's dynamic and row index changes based on the inputs and type of the input. what i'm trying to do is capture the subtotal in cell. so i could get the total from the returned row and given columnindex. i've three subtotals section. i want to capture the row index from the first subtotal row but , my code always returns the last subtotal's row index. how can i capture the very first subtotal row index. any help would be highly appreciated. 

please see my below code

 

Set objTxt=MainPage.FindChild(Array("ObjectType","contentText"),Array("Cell","Sub Total"),100,true)
i=0
Do While Not (objTxt.Exists)And i<5
aqUtils.Delay(1000)
Set objTxt=MainPage.FindChild(Array("ObjectType","contentText"),Array("Cell","Sub Total),100,true)
i=i+1
Loop
If (objTxt.Exists) Then 'get the rowIndex
intRwIndex=aqObject.GetPropertyValue(objTxt,"RowIndex")
End IF

3 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Hi,

 

The best, fastest and most reliable solution is to talk to Development and ask them to provide unique and stable identifiers for all UI elements that your test code needs to work with.

If this is not an option, then you still may try .FindAllChildren() and use the fact that the first subtotal section will be the last element of the returned array. This is not documented, but this is how .FindAllChildren() and .FindChild() work for more then decade since their implementation.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Hi,

 

Not sure I got the question...
The code seems to be fine...

To get the first UI object just use the last found one:

Set myObject = arrobjects(UBound(arrobjects)) ' last found object corresponds to the first UI one

What I am missing?

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Frequent Contributor

Re: struggling to retrieve the first value found in a web table based on expected text

Thanks  a lot Alex,,, it works just fine,,,,,,,,,,,,,,,,,, i'm able to use capture the desired row and use that row to capture the amount. I really appreciate your help. Cheers!

View solution in original post

10 REPLIES 10
Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Move your if then logic inside your loop, do your "exists" check and, if it returns true, set your intRwIndex variable to the object row index (You can just do intRwIndex = objTxt.RowIndex, need need to GetPropertyValue), and then Exit the loop with an "Exit For" statement.  I'm not VERY good at VB Script, but this is how I think it should look:

Set objTxt=MainPage.FindChild(Array("ObjectType","contentText"),Array("Cell","Sub Total"),100,true)
i=0
Do While Not (objTxt.Exists)And i<5
aqUtils.Delay(1000)
Set objTxt=MainPage.FindChild(Array("ObjectType","contentText"),Array("Cell","Sub Total),100,true)
If (objTxt.Exists) Then 'get the rowIndex
intRwIndex=objTxt.RowIndex
Exit For
End IF
i=i+1
Loop

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Frequent Contributor

Re: struggling to retrieve the first value found in a web table based on expected text

thanks, but for some reason it starts from the buttom. and returns me the last rowindex number for the subtotal. is there a way to use index number or something

Set objTxt=MainPage.FindChild(Array("ObjectType","contentText"),Array("Cell","Sub Total"),100,true)
If (objTxt.Exists) Then 'get the rowIndex
intRwIndex=objTxt.RowIndex
msgbox intRwIndex
End IF

thanks

Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

That's FindChild.  The results from FindChild always start at the bottom.

Suggestion... rather than doing your search from the MainPage... what if you mapped the Table itself (you're looking for Cells, there has to be a table.  You can Alias it down to simply MainPage.MyTable if you want to.

 

With that, you could just do a for-loop through the table... that will do a top down.  Something like this (JavaScript, sorry... I'm not a VB guy).  The assumption below is that the column index for the "Sub-Total" is 2... you can change that to whatever you want.

 

var myObject;
var intRowIndex;
for (var i; i < Aliases.MainPage.MyTable.RowCount -1, i++){
    if (Aliases.MainPage.MyTable.Cell(i, 2).contentText == 'Sub-Total'){
        myObject = Aliases.MainPage.myTable.Cell(i,2);
        intRowIndex = i;
        break;
    }

}

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Frequent Contributor

Re: struggling to retrieve the first value found in a web table based on expected text

thank you so much, sounds like i plan, i'll try it and let you know how it goes. have a nice weekend.

Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Hi,

 

Also, instead of .FindChild() you may try .FindAllChildren() which will return you and array of found cells. Then you may iterate through the array and sum subtotals to get the grand total.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Frequent Contributor

Re: struggling to retrieve the first value found in a web table based on expected text

Hi Alex , yeah sub total makes up the grand total, my requirement is to just capture the subtotal from the top section , and whatever the types are below subtotal section capture all and the verify the grand total,,,, I am only struggling with capturing the subtotal from the top section ,, I will try all the suggested approach on Monday and update !! Thanks a lot
Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Hi,

 

The best, fastest and most reliable solution is to talk to Development and ask them to provide unique and stable identifiers for all UI elements that your test code needs to work with.

If this is not an option, then you still may try .FindAllChildren() and use the fact that the first subtotal section will be the last element of the returned array. This is not documented, but this is how .FindAllChildren() and .FindChild() work for more then decade since their implementation.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Frequent Contributor

Re: struggling to retrieve the first value found in a web table based on expected text

Hi Alex, 

thanks for your suggestion. actually we use a vendor product, don't have access to the developers. 

actually i am able to find all in an array, now how can i use it. need to capture the last returned rowindex number,,, not sure how can capture it so i can use that to grab the value , please see the code

Sub FindRwIndex

Dim myObject,rwIndex

Set mytable =Aliases.browser.Page.MyPremTable

arrobjects=mytable.FindAllChildren("contentText","Sub Total")
for arrCount=0 To UBound(arrobjects)
If arrobjects(arrCount).contentText="Sub Total" Then
'Set myObject=arrobjects(arrCount)
rwIndex=arrobjects(arrCount).RowIndex
Log.Message rwIndex
End If
Next
End Sub

Highlighted
Community Hero

Re: struggling to retrieve the first value found in a web table based on expected text

Hi,

 

Not sure I got the question...
The code seems to be fine...

To get the first UI object just use the last found one:

Set myObject = arrobjects(UBound(arrobjects)) ' last found object corresponds to the first UI one

What I am missing?

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors