Hello,
I'm attempting to click on a specific row of an HTML table in my user code determined by a randomly generated int.
I've attached a snapshot of my table which is focused on a cell, one item further than the one I'm attempting. In my repository, I've modified the XPath of my element (cellByNum) with a variable for the row:
div[3]/div[2]/div/div[2]/table/tbody/tr[$rowNum]
In Ranorex Spy, when I replace $rowNum with actual values, the expected rows are highlighted. However, in my user code, when I replace my variable there (also called rowNum... I know, I know, I'll fix it) with actual values, absolutely nothing happens so I know that I'm doing something very wrong... sigh.
This is my user code to try to click the row:
repo.BlazorClient.IndividualsPage.cellByNum.Click(rowNum);
If someone could please tell me how I should be doing this, I would greatly appreciate it.
Thanks so much.
Clicking a Specified Row in HTML Table
Clicking a Specified Row in HTML Table
You do not have the required permissions to view the files attached to this post.
Re: Clicking a Specified Row in HTML Table
Hi,
This does not make sense:
If the repo variable rowNum is connected to a data connector of your choice (containing the rowNumber) and properly filled, it should be enough to use Click method without parameter...
For example, you can use xpath like this, to find the appropriate cell by the 'Last Name':
Or both Last and First Name:
Then simply replace the 'innertext' strings with variables and connect them to a data connector of your choice.
Also, I would suggest not to call the repo items directly in code, but rather pass the repo item as a parameter to user code method.
This does not make sense:
Click method does not accept "row number" as a parameter. So entering 'rowNum' in Click method is useless.repo.BlazorClient.IndividualsPage.cellByNum.Click(rowNum);
If the repo variable rowNum is connected to a data connector of your choice (containing the rowNumber) and properly filled, it should be enough to use Click method without parameter...
Anyway, the whole concept of clicking cell by its row number or index is weird and potentially failing. Why don't you click the cell containing certain name? Or a combination of first and last name?repo.BlazorClient.IndividualsPage.cellByNum.Click();
For example, you can use xpath like this, to find the appropriate cell by the 'Last Name':
Code: Select all
/dom[@domain='localhost:5001']//table[@class='mud-table-root']//td[@data-label='Last Name' and @innertext='Ahle']
Code: Select all
/dom[@domain='localhost:5001']//table[@class='mud-table-root']//td[@data-label='Last Name' and @innertext='Ahle']/ancestor::tr/td[@data-label='First Name' and @innertext='Delmy']
Also, I would suggest not to call the repo items directly in code, but rather pass the repo item as a parameter to user code method.
Code: Select all
public void ClickTableCell(RepoItemInfo repoElement)
{
Ranorex.TdTag cellAdapter = repoElement.CreateAdapter<Ranorex.TdTag>(false);
cellAdapter.Click();
}
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
Re: Clicking a Specified Row in HTML Table
Thanks, Pavel.
Clearly, I need to refresh my C# coding skills. I do understand what you're saying; my intent was to randomly click a row (but I suppose that I could randomly click a cell instead) and then I'm doing a compare of what appears in the row selected and what appears in the header (that part I have working).
I think that you've, again, pointed me the right direction.
Thanks again.
Clearly, I need to refresh my C# coding skills. I do understand what you're saying; my intent was to randomly click a row (but I suppose that I could randomly click a cell instead) and then I'm doing a compare of what appears in the row selected and what appears in the header (that part I have working).
I think that you've, again, pointed me the right direction.
Thanks again.
Re: Clicking a Specified Row in HTML Table
Hello,
I just wanted to post an update on this since I was actually able to implement what I was attempting to do from the start.
What finally worked was the following:
Created a table adapter for the HTML table, then iterated through the HTML table to get the ChildIndex of each row. The ChildIndex corresponds to my loop counter (iRow). I have a separate method getting a random int. When iRow is equal to my random int, the row is clicked.
It took me a while to get here and the assistance from Pavel really helped!
Thanks again.
I just wanted to post an update on this since I was actually able to implement what I was attempting to do from the start.
What finally worked was the following:
Created a table adapter for the HTML table, then iterated through the HTML table to get the ChildIndex of each row. The ChildIndex corresponds to my loop counter (iRow). I have a separate method getting a random int. When iRow is equal to my random int, the row is clicked.
It took me a while to get here and the assistance from Pavel really helped!
Thanks again.