This is a migrated thread and some comments may be shown as answers.

Finding one element in row, then clicking previous element

4 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 16 Dec 2014, 03:54 PM
I have a table of data where I am trying to find a specific row in the table using data from an excel spreadsheet, and then I want to click a checkbox at the beginning of the row. There are several other steps that will cause the row to be deleted, then I want to run the test again using the next search term in the excel file. I can find the particular row I am looking for by using a chained find to find the table itself, and then the row, but I can't figure out how to back up in the same row to a previous element.

Can I do this test using the UI? I'd like to take advantage of the data binding of the excel data to my test steps.

If I can only do this test using code, can you show me the code I would need to use, including the code to read in the data from my excel file?

I've attached the relevant section of the DOM, the table I am searching. I am using version 2014.3.903.0 of Test Studio. If there is anything else you need, let me know.

4 Answers, 1 is accepted

Sort by
0
Alan
Top achievements
Rank 1
answered on 17 Dec 2014, 04:18 PM
After thinking about this more, I think I can use the recorded steps up to the point I find the row I am looking for, then just add one coded step to back up and click the checkbox. After that I can continue with the recorded steps. I am assuming that Test Studio keeps track of the last element found and I can assign that last element to a variable, then use that to back up to the previous checkbox. Can I get the code for this smaller piece of my test? Or let me know if my assumptions are incorrect.
0
Accepted
Boyan Boev
Telerik team
answered on 19 Dec 2014, 11:52 AM
Hi Alan,

Could you please elaborate a bit more. What do you mean to back up in the same row? Do you want to click the check box which is let's say the first column of the row? If this is the case you have two options here:

1. Create a chained find expression as you did for the row. You should look for the input element in the particular row.

2. Use a coded step. Find the input element withing the row:

HtmlInputCheckBox checkbox = Pages.YourAPP.YourRwo.Find.ByExpression<HtmlInputCheckBox>("tagname=input", "type=checkbox");
 
checkbox.Check(true, true);

Let me know if I am missing something.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Alan
Top achievements
Rank 1
answered on 23 Dec 2014, 08:23 PM
Boyan,

I was able to get my test working using the piece of code you included in your answer. Thanks.

Here is the code I used. This code finds the correct row by searching on the element in column 2, extracts the row id and saves it for later, checks the checkbox in column 1, and then waits for the row to be deleted using the extracted row id.

            'find correct row using bound data source
            Dim userAssignTable as HtmlTable = Pages.ResourceAllocation.UserToBeAssignedTable()
            Dim row as HtmlTableRow = userAssignTable.Find.ByContent(Of HtmlTableCell)(Data("Order Label")).Parent(Of HtmlTableRow)()
            'get row id and extract to variable
            Dim rowID as String = row.Attributes.[Single](Function(x) x.Name = "id").Value
            SetExtractedValue("rowSelected",rowID)
            'find checkbox in row and check
            Dim chkbox as HtmlInputCheckBox = row.Find.ByExpression(Of HtmlInputCheckBox)("tagname=input", "type=checkbox")
            chkbox.Check(true, true)

There were a couple of recorded steps here, then the coded step to wait for the row to get deleted:

            Dim rowIDToDelete As String = GetExtractedValue("rowSelected")
            Pages.ResourceAllocation.Get(Of ArtOfTest.WebAii.Controls.HtmlControls.HtmlTableRow)(New ArtOfTest.WebAii.Core.HtmlFindExpression("id=(rowIDToDelete)", "tagname=tr"), false, 0).Wait.ForExistsNot(30000)
0
Boyan Boev
Telerik team
answered on 24 Dec 2014, 06:00 AM
Hi Alan,

I am glad to hear that. 

If you need further help please let us know.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Alan
Top achievements
Rank 1
Answers by
Alan
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or