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.
How to get last row of Grid
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get last row of Grid
Hello,
You could use the method 'last()' in your RxPath as shown below:
Alternatively, you could use the method 'count()' to find out the number of rows and use it as index (see example code below):
Markus (T)
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']
// 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)
Re: How to get last row of Grid
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 -
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.
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();
FYR, I have attached RX snapshot of related grid on which I am designing scripts. Please review that.
Thanks,
Varun.
You do not have the required permissions to view the files attached to this post.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get last row of Grid
Hi Varun,
In your case I would use one of these methods :
Markus
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
Re: How to get last row of Grid
Hi Markus,
Thank you for the snippet, unfortunately it's not working. I am using following user code -
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.
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();
}
Regards,
Varun.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get last row of Grid
Hi,
Are you sure that the "lastrow" variable was used?
Could you post the code snippet of the specific script?
Thanks,
Markus
Could it be that you used the repo item in the script which was added when your recorded the action?but then also script is executing the row on which recording was done.
Are you sure that the "lastrow" variable was used?
Could you post the code snippet of the specific script?
Thanks,
Markus
Re: How to get last row of Grid
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.
Your feedback awaited!
Thanks in advance,
Varun.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get last row of Grid
Hi,
What happens if you perform a Click() instead of a Focus()?
Regards,
Markus
What happens if you perform a Click() instead of a Focus()?
Regards,
Markus
Re: How to get last row of Grid
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.
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get last row of Grid
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:
Markus
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