Highlighted
Absent Member.
Absent Member.
3806 views

Search rows in a webtable for text, then output the value

Jump to solution
Hi,

I’m hoping someone can help me. I have a WebTable in a SAP application that I am trying to search through to find a specific text value, once found, to output the value of every cell on the row the text was found in.

For instance, I have a table with 4 columns and many rows, one or more of the columns contain the text I want, I need the script to loop through each row until it finds the text I am looking for, then output the text value in each cell on that row. The loop would end once it find a row with no data.


Any help would be much appreciated.

Thanks in advance,
Sean
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.
Try looking at it again, sometimes it'll skip over the webtable in the steps....Also sometimes if you click right on the text it will show up as a webelement.


Use an object spy and attach a screenshot of said object spy on the object.


Anyways You could always just iterate through with two for loops.

for i = 1 to rowcount
for j = i to columncount
if WebTable.GetCelldata(i,j) = "yourText" Then
'iterate through that row and concatenate
Exit For
Exit For
End If
Next
Next



Something along those lines as far as pseudocode goes

View solution in original post

14 Replies
Highlighted
Absent Member.
Absent Member.
Will GetRowWithCellText help you ? This will return the row number which contains the specified text.
0 Likes
Highlighted
Absent Member.
Absent Member.
Hi Reju,

well I am confused on how to write this within a while statement. I actually need the text to write to output so that I can store the values in Excel,etc later. Could you give me a general example of the code you would use to solve this?
0 Likes
Highlighted
Absent Member.
Absent Member.
well the syntax is like this....

rowNo = Browser().Page().WebTable().GetRowWithCellText("Search Word")

This will return to you the row number of the table where this text is located...
0 Likes
Highlighted
Absent Member.
Absent Member.
HI Reju,

Thanks again for your help. Seems the object is not an actual table, which is my problem all along. The object I am dealing with is a WebElement, though has simialr functions. ???


Is there any way to do this with this type of object:
Browser("").Page("").Frame("").WebElement("")
0 Likes
Highlighted
Absent Member.
Absent Member.
Try looking at it again, sometimes it'll skip over the webtable in the steps....Also sometimes if you click right on the text it will show up as a webelement.


Use an object spy and attach a screenshot of said object spy on the object.


Anyways You could always just iterate through with two for loops.

for i = 1 to rowcount
for j = i to columncount
if WebTable.GetCelldata(i,j) = "yourText" Then
'iterate through that row and concatenate
Exit For
Exit For
End If
Next
Next



Something along those lines as far as pseudocode goes

View solution in original post

Highlighted
Absent Member.
Absent Member.
Hross,

Thanks! I did just what you said, it took a bit, but it did find the cells and the table. Seems it was a table within a table that through me off. I am able to identify the separate cells for output now using GetCellData. Now I am just trying to figure out the â Forâ statement to get the script to drop one row at a time until there is no more data found for out put. I decided it was best to grab all the data from all the rows, regardless of the text found. I can also sort it out later.

Sorry, I am new to VBScript and trying to catch up. Can you provide an example for me based on that, or would what you already provided work?
0 Likes
Highlighted
Absent Member.
Absent Member.
Ok. I was able to get the cell data, following like steps that you gave me. Thanks!!

Iâ m having a problem getting the output store on the Data Table for the different Web Table rows.

IE, I want the output on the Data table to mimic what the Web Table shows, row 1 of the Web Table on row 1 of the data table (output), row 2 of the Web Table on row 2 of the data table (output), etc for all the rows on a given table so I can then paste over to Excel and sort it.

Is this possible? All I get is the data being written to the same row of the datatable over and over again (for the # rows in the Webtable).

Please let me know if you need more information from me. I may not be all that clear.

Thanks in advance, I really appreciate all the help!!!
0 Likes
Highlighted
Absent Member.
Absent Member.
If you followed hross's solution then just set the datatable row before the second loop.
That should avoid overwriting the same row.


for i = 1 to rowcount
DataTable.SetCurrentRow(i)
for j = i to columncount
......
Next
Next




Highlighted
Absent Member.
Absent Member.
thats was the ticket!! thanks you very much, my script is running great now. because Im using account numbers to go into different accounts and grab these tqble items, I now just need to figure out how to get the account numebr and write the new table data rows after the last table row from the previous account. Here is the code I am using.

Dim accountnumber
accountnumber = DataTable("GetAcctNumber", dtLocalSheet)
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").WebEdit("C4_W22_V23_buagsearch_struct.z").Set DataTable("GetAcctNumber", dtLocalSheet)
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").Link("Search").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").Link("Account History").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Account").Frame("WorkAreaFrame1").WebElement("WebTable").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Account").Frame("WorkAreaFrame1").WebElement("Sort Descending").Click

RCount = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").RowCount

For r = 1 to RCount
DataTable.SetCurrentRow(r)
Info1 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 1)
Info2 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 2)
Info3 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 3)
Info4 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 4)
DataTable("Account", "payment_scrub") = accountnumber
DataTable("Payment_Amount", "payment_scrub") = info1
DataTable("Posting_Date", "payment_scrub") = info2
DataTable("Currency_Type", "payment_scrub") = info3
DataTable("Description", "payment_scrub") = info4
Next
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("FRAME_CONTEXTAREA").Link("End Contact").Click
Browser("PDS Broker").Page("PDS Broker").Sync
0 Likes
Highlighted
Absent Member.
Absent Member.
Try this

Dim accountnumber
RowNum=0

For RowNum=1 to DataTable.GetRowCount
accountnumber = DataTable("GetAcctNumber", dtLocalSheet)

Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").WebEdit("C4_W22_V23_buagsearch_struct.z").Set DataTable("GetAcctNumber", dtLocalSheet)
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").Link("Search").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("WorkAreaFrame1").Link("Account History").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Account").Frame("WorkAreaFrame1").WebElement("WebTable").Click
Browser("Interaction Center - [Identify").Page("Interaction Center - [Account").Frame("WorkAreaFrame1").WebElement("Sort Descending").Click

RCount = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").RowCount

For r = 1 to RCount
DataTable.SetCurrentRow(RowNum+r)
Info1 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 1)
Info2 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 2)
Info3 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 3)
Info4 = Browser("Interaction Center - [Identify").Page("Interaction Center - [Account_4").Frame("WorkAreaFrame1").WebTable("Amount").GetCellData(r, 4)
DataTable("Account", "payment_scrub") = accountnumber
DataTable("Payment_Amount", "payment_scrub") = info1
DataTable("Posting_Date", "payment_scrub") = info2
DataTable("Currency_Type", "payment_scrub") = info3
DataTable("Description", "payment_scrub") = info4
Next
RowNum=RowNum+RCount

Browser("Interaction Center - [Identify").Page("Interaction Center - [Identify").Frame("FRAME_CONTEXTAREA").Link("End Contact").Click
Browser("PDS Broker").Page("PDS Broker").Sync
Next
ExitRun
Highlighted
Absent Member.
Absent Member.
Sorry made a mistake...
change the third line to the following.


For Iterations=1 to DataTable.GetRowCount
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.