Dynamic element identification and clicking

Ask general questions here.
Santhosh R
Posts: 10
Joined: Mon Mar 02, 2020 6:00 am

Dynamic element identification and clicking

Post by Santhosh R » Wed Apr 28, 2021 8:49 am

Hi Team,
We have to retrieve all the elements (Name, Type & data) and push all the retrieved items in to list which are in screenshot below. We will pass one parameter based on the parameter we need to click the element.
How shall we design this requirement and how will implement this scenario using element identification and Xpath through C# code.
Please do the needful.
Please refer below screenshot for element identification and clicking the element dynamically
RegKey.PNG
RegKey.PNG (35.03 KiB) Viewed 100 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6544
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Dynamic element identification and clicking

Post by odklizec » Wed Apr 28, 2021 10:12 am

Hi,

Here is a basic example, how to access rows/cells in regedit table. Basically, you must create a repo element, pointing to regeditor table, like this:

Code: Select all

/form[@title='Registry Editor']/table[@class='SysListView32' and @accessiblerole='List']
And then you must pass this repo element to method like this, which will help you to enumerate and read individual table rows/cells...

Code: Select all

public void EnumerateRows(RepoItemInfo repoTableElement)
    {
        string cellText = "";
        Ranorex.Table tableAdapter = repoTableElement.CreateAdapter<Ranorex.Table>(false);
        foreach (var rowItem in tableAdapter.Rows)
       {
            foreach (var rowCell in rowItem.Cells)
            {
                cellText = rowCell.Element.GetAttributeValueText("Text"); //reads content of each cell
            }
        }
    }
Of course, this is just a rough sample, which you must edit according your needs ;)
Pavel Kudrys
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

Santhosh R
Posts: 10
Joined: Mon Mar 02, 2020 6:00 am

Re: Dynamic element identification and clicking

Post by Santhosh R » Mon May 10, 2021 6:18 am

Hi,

We have an another issue while fetching the data from Control Panel/Programs and Features.
We have to retrieve all elements from program and features and push all the retrieved items in to list which are in screenshot below. We will pass one parameter based on the parameter we need to click the element.
How shall we design this requirement and how will implement this scenario using element identification and Xpath through C# code.
Please do the needful
Control Panel.PNG
Control Panel.PNG (66.1 KiB) Viewed 16 times
Thanks

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6544
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Dynamic element identification and clicking

Post by odklizec » Mon May 10, 2021 8:38 am

Hi,

It's the same approach, as with the Registry editor. Basically, you must construct an xpath, which returns all elements from the first column (at least I assume, that you want to get names of all programs?).

Code: Select all

/form[@title='Programs and Features']//table[@class='SysListView32']/row/cell[1]
Then simply use the above code, to process the individual elements, to click them, or do whatever you want to do with them (e.g. get their names/texts). Of course, you must adapt the code according your needs.
ProgramAndFeatures.png
ProgramAndFeatures.png (119.06 KiB) Viewed 10 times
Pavel Kudrys
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