accessing a repository item using a counting variable

Best practices, code snippets for common functionality, examples, and guidelines.
prostennik
Posts: 3
Joined: Fri Dec 09, 2016 10:35 am

accessing a repository item using a counting variable

Post by prostennik » Mon Jun 26, 2017 11:47 am

Hi,

I have a grid input control with up to 80 lines. I need to dynamically change the line I am accessing according to the amount of items that have been entered already, these item counts differ depending on runtime variables so they may end up on different Rows dependent upon runtime:

Row1_Input
Row2_input
...
Row80_Input

I have a variable counting the amount of items already entered , what I want is to enter Row_Input so the next item is automatically entered on the correct line. Ghost code would be something like:

for i in rows:
repo.grid.Row_Input.PressKeys("Item");

Am I thinking completely incorrectly here? Anyone tell me where I am going wrong please?

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: accessing a repository item using a counting variable

Post by RobinHood42 » Mon Jun 26, 2017 2:19 pm

Hi,

it would be great if you could provide more information. A Ranorex snapshot file would allow us to better understand your application under test.

Snapshot file: https://www.ranorex.com/support/user-gu ... pshot.html
I have a variable counting the amount of items already entered , what I want is to enter Row_Input so the next item is automatically entered on the correct line. Ghost code would be something like:

So, basically, you just want to get the first row, which doens't have any input value, correct?

Cheers,
Robin 8)

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: accessing a repository item using a counting variable

Post by Vaughan.Douglas » Mon Jun 26, 2017 3:02 pm

Something along these lines might work best. We could provide a more accurate sample if we had a snapshot so we knew what types we were dealing with.
foreach (var myRow in myRepo.Root.TableWithRow.FindDescendants<Ranorex.Row>())
            {
                myRow.FindSingle<Ranorex.Unknown>("RxPath").PressKeys("Item");
            }
Doug Vaughan

prostennik
Posts: 3
Joined: Fri Dec 09, 2016 10:35 am

Re: accessing a repository item using a counting variable

Post by prostennik » Tue Jun 27, 2017 6:48 am

Hi,

snapshot attached. And yes, basically I just want to write an item in the next row with no current value written.
I was looking at findsingle and assumed I would land there, but I was not able up to now to get it working. :shock:

Thanks
Attachments
sapgrid.rxsnp
(189.52 KiB) Downloaded 14 times

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: accessing a repository item using a counting variable

Post by RobinHood42 » Tue Jun 27, 2017 9:12 am

Hi,

Thank you for uploading the snapshot file.

Maybe the following code snippet helps you.
Table sapTable = "/form[@connectiondescription='QCA [SPACE]']//table[@name='SAPMV45ATCTRL_U_ERF_ANGEBOT']";

            foreach (var row in sapTable.FindChildren<Row>())
            {
                foreach (var cell in row.FindChildren<Cell>())
                {
                    if (String.IsNullOrEmpty(cell.Text))
                    {
                        //Do anything
                        cell.Click();
                    }
                }
            }
The code finds all cells within your table, which do not have a text.

Cheers,
Robin 8)

prostennik
Posts: 3
Joined: Fri Dec 09, 2016 10:35 am

Re: accessing a repository item using a counting variable

Post by prostennik » Tue Jun 27, 2017 12:08 pm

works perfectly :mrgreen:

Many thanks Robin. I was going the right way, but I am not sure I would have arrived :)