How to get last row of Grid

Ranorex Spy, Recorder, and Studio.
varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

How to get last row of Grid

Post by varun » Tue Dec 18, 2012 2:50 pm

Hi Support,

In a web page, 4 to 6 rows are there. Count of rows are not fixed. On click on New button of the page, inserts a new row at last(having some fields) on which we have to work.
My question is, after click on New link button, How can I drive RX to move directly on last row of the page ?

Thanks in advance,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get last row of Grid

Post by Support Team » Wed Dec 19, 2012 2:14 pm

Hello,

You could use the method 'last()' in your RxPath as shown below:

Code: Select all

/dom[@caption='Ranorex Test Page']//table[#'simpletable']/tbody/tr[last()='True']
Alternatively, you could use the method 'count()' to find out the number of rows and use it as index (see example code below):
// get all rows (which are TrTags) in a table
var rows = Host.Local.Find<Ranorex.TrTag>("/dom[@caption='Ranorex Test Page']//table[#'simpletable']/tbody");
int rowNumber = rows.Count; // store number of rows in a variable
// get last row by using row count
var lastRow = Host.Local.Find<Ranorex.TrTag>("/dom[@caption='Ranorex Test Page']//table[#'simpletable']/tbody/tr[" + rowNumber + "]");
Regards,
Markus (T)
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to get last row of Grid

Post by varun » Thu Dec 20, 2012 11:13 am

Hi Markus,

Thank you for reply. On spy I can easily track last element. But not working when used in combination with code snippet. I am using following code snippet, to move focus on last row -

Code: Select all

var lastrow = Host.Local.FindSingle("/dom[@domain='xeonserver1']//table[#'dgHistory']//tr[Last()='True']");
lastrow.Focus();
After this, code is there to work with fields on last row.
FYR, I have attached RX snapshot of related grid on which I am designing scripts. Please review that.

Thanks,
Varun.
Attachments
History_1220.rxsnp
History
(354.66 KiB) Downloaded 211 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get last row of Grid

Post by Support Team » Fri Dec 21, 2012 3:35 pm

Hi Varun,

In your case I would use one of these methods :
TrTag lastrow = "/dom[@domain='xeonserver1']//table[#'dgHistory']//tr[last()='True']";
//OR
TrTag lastrow = Host.Local.FindSingle<TrTag>("/dom[@domain='xeonserver1']//table[#'dgHistory']//tr[last()='True']");
Regards,
Markus
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to get last row of Grid

Post by varun » Wed Dec 26, 2012 6:45 am

Hi Markus,

Thank you for the snippet, unfortunately it's not working. I am using following user code -

Code: Select all

public void Goto_LastRow()
        {
        	TrTag lastrow = Host.Local.FindSingle("/dom[@domain='xeonserver1']//table[#'dgHistory']//tr[Last()='True']");
        	lastrow.Focus();
        }
Although path of last law is passed in "lastrow" var but then also script is executing the row on which recording was done.

Regards,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get last row of Grid

Post by Support Team » Thu Dec 27, 2012 11:32 am

Hi,
but then also script is executing the row on which recording was done.
Could it be that you used the repo item in the script which was added when your recorded the action?
Are you sure that the "lastrow" variable was used?
Could you post the code snippet of the specific script?

Thanks,
Markus
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to get last row of Grid

Post by varun » Tue Jan 15, 2013 11:51 am

Markus, I am using the same script which is posted in my last post. Could you please check and clear me what needs to be done here for this. I assume something is wrong with "lastrow.Focus()" but not sure.
Your feedback awaited!

Thanks in advance,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get last row of Grid

Post by Support Team » Tue Jan 15, 2013 4:06 pm

Hi,

What happens if you perform a Click() instead of a Focus()?

Regards,
Markus
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to get last row of Grid

Post by varun » Wed Jan 16, 2013 6:09 am

Hi Markus,

Using ".click()" makes it to click on last row but again for rest of steps, tool continues from the row on which recording was done. I guess you have RX snapshot, so please look into it and kindly let me know what can be done to come over this issue.

Thanks,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get last row of Grid

Post by Support Team » Thu Jan 17, 2013 7:15 pm

Hi,

Which action was the last action which was executed before you want to set the focus on the last row, the click on the "Add" button?
Do you have tried it with the click?
How would you manually set the focus on the last row?
Do you have already tried to set the focus on a specific cell (TdTag) of that row?
If not please give it a try.
You could also try to move with the mouse to the element before you focus on the element:
yourTdTag.MoveTo("0;0");
        	YourTdTag.Focus();
Regards,
Markus
.
Image