How to store elements in a list and then click on any one of them

Ask general questions here.
premravi
Posts: 78
Joined: Tue Jan 08, 2019 1:55 pm

How to store elements in a list and then click on any one of them

Post by premravi » Fri Apr 26, 2019 4:03 pm

Hi,

I am working on a scenario wherein I have to store bunch of elements from a drop down into a list and then select any of them whichever I wish

That selection will also be variable base like parameterization, NO HARDCODING" any one specific value

Please help me how to store elements in a list

Please let me know for more info

Regards

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

Re: How to store elements in a list and then click on any one of them

Post by Support Team » Fri Apr 26, 2019 9:06 pm

Hi premravi,

With more information, including a Ranorex Snapshot, I may be able to better assist you. Nonetheless, please see the below as it may be enough to point you in the right direction.

To add all options of a select box to a list, first, create an item in your Ranorex Repository which points to all option tags of the desired select box element, for example:

Code: Select all

./?/?/select/option
Next, use the following code to create a Ranorex OptionTag Adapter for each option returned from the above repository item (named allOptionElements in the example below). This will store each option element in a list so you can hopefully achieve what you need.

Code: Select all

var repo = SampleProjectRepository.Instance;
var allOptionElements = repo.myDom.allOptionElementsInfo;

IList<OptionTag> allOptions = allOptionElements.CreateAdapters<OptionTag>();
foreach (OptionTag option in allOptions) 
	Report.Info(option.Element.GetAttributeValueText("Value"));
I hope this helps!

Regards,
Ned
.
Image

premravi
Posts: 78
Joined: Tue Jan 08, 2019 1:55 pm

Re: How to store elements in a list and then click on any one of them

Post by premravi » Mon Apr 29, 2019 10:42 am

Hi,

Please find the attached image and the snapshot which helps you in designing the xpath and code snippet as well

Regards
Attachments
dropdowncode.png
dropdowncode.png (77.3 KiB) Viewed 326 times
DropDownElements.rxsnp
(130.91 KiB) Downloaded 19 times

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

Re: How to store elements in a list and then click on any one of them

Post by odklizec » Mon Apr 29, 2019 11:23 am

Hi,

We've discussed a similar topic few days ago here:
viewtopic.php?f=4&t=13773&p=53973#p54021
Basically, you should use the same approach, mentioned in this post.

I just don't understand the need of creating list of elements, if you simply want to click one of available table elements? If you need to click just one particular element, you can use xpath like this:

Code: Select all

/dom[@domain='dashboard.eu-iport.nielsen-iwatch.com.aws-w-np.nielsencsp.com']//div[@class='edit-view-container']/?/?/div[@class='left-panel-container']//div[@class='navbar jqx-reset jqx-widget jqx-navigationbar']//div[@class='user-image-list tree-grid']/?/?/div[@class='mj-treegrid-container']//table/tbody/tr/td//div[@class='mj-text mj-nowrap']/span[@class='text' and @innertext=$itemName]
Where itemName variable you can simply bind to a data connector of your choice and fill it from there with name of item you want to click. No list and code is needed then.

In case you prefer to create coded list and do all clicking via code, you should follow the above linked post. To create list of available elements, you should use xpath like this:

Code: Select all

/dom[@domain='dashboard.eu-iport.nielsen-iwatch.com.aws-w-np.nielsencsp.com']//div[@class='edit-view-container']/?/?/div[@class='left-panel-container']//div[@class='navbar jqx-reset jqx-widget jqx-navigationbar']//div[@class='user-image-list tree-grid']/?/?/div[@class='mj-treegrid-container']//table/tbody/tr/td//div[@class='mj-text mj-nowrap']/span[@class='text']
This xpath simply returns all span elements from the table of your choice.
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

premravi
Posts: 78
Joined: Tue Jan 08, 2019 1:55 pm

Re: How to store elements in a list and then click on any one of them

Post by premravi » Mon Apr 29, 2019 4:10 pm

Hi,

Thanks a lot for your response,

Yes I remember we discuss this before, but the requirement is bit different from the previous one

I do not have to click on all elements available in the drop down

I just want to click on any one whichever I will pass it in a variable

Basically I am trying to store all the elements which are available in the list into a "variable" and then I can pass any value through that variable and it will click to that specific value

Please help to design this piece of code

I am trying but getting few errors

Please find the attached screenshot
Attachments
SpanListError.png
SpanListError.png (148.21 KiB) Viewed 310 times

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

Re: How to store elements in a list and then click on any one of them

Post by odklizec » Mon Apr 29, 2019 6:24 pm

premravi wrote:
Mon Apr 29, 2019 4:10 pm
I just want to click on any one whichever I will pass it in a variable
And here is why I don’t understand the need to store all items in variables or list. All you need is a ‘global’ repoitem, pointing to all items of given type in table and where InnerText attribute is filled with variable. Now once the variable is filled, preferably from data connector, xpath finds exactly the element you want to click. And that’s all you need. No code is required at all ;)
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

premravi
Posts: 78
Joined: Tue Jan 08, 2019 1:55 pm

Re: How to store elements in a list and then click on any one of them

Post by premravi » Tue Apr 30, 2019 11:18 am

LOL!!....... :lol: :lol:

Sure, I will follow this approach,

As far as I understand, you try to avoid writing code wherever possible :wink:

But your suggestions are really helpful :D

Regards

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

Re: How to store elements in a list and then click on any one of them

Post by odklizec » Tue Apr 30, 2019 11:28 am

Hi,

You are right. I just don't like over complicate simple things :D RanoreXpaths are quite powerful and a lot of things can be done with them. Custom code is of course necessary in TA, no matter what tell us various marketing materials. But there is really no point to code something, that can be achieved by much more elegant way. And another reason is, that each line of custom code is a potential source of bugs ;)
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

premravi
Posts: 78
Joined: Tue Jan 08, 2019 1:55 pm

Re: How to store elements in a list and then click on any one of them

Post by premravi » Tue Apr 30, 2019 4:27 pm

Hi,

The similar kind of requirement I come up with with a small tweek in it

Basically now I have to search for a file in the file explorer window

I am following the approach of presskeys the name of the file and click open it is working

As of now the name of the file is hardcoded

I have to store it in a variable and call it whichever file name I want

I tried it but its not working

Please find attached screenshot and snapshot

Inside Form Open >>>>Text 1148 is the location of the text field in the file explorer native window
Attachments
FileExplorer.rxsnp
(117.84 KiB) Downloaded 11 times
selectImageFromFileExplorer.png
selectImageFromFileExplorer.png (124.33 KiB) Viewed 284 times

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

Re: How to store elements in a list and then click on any one of them

Post by Support Team » Tue Apr 30, 2019 8:06 pm

Hi Premravi,

For this, you should be able to use a standard recorder variable and bind it to a parameter. I highly recommend checking out this part of our user guide as it goes into depth on this topic. The pictures below may also better explain what is recommended to achieve this.
1.png
1.png (5.55 KiB) Viewed 278 times
2.png
2.png (16.05 KiB) Viewed 278 times
Cheers,
Ned
.
Image