Code for Adding from the dropdown list

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Code for Adding from the dropdown list

Post by maamer » Wed Dec 12, 2018 7:44 pm

i have a problem, i am trying to write a custom code that will take value from user and click on the value in the drop down list to add widget. so far my code is
public static void AddWidget(RepoItemInfo selecttaginfo, string widgetname)
var repo = BottomLineIIRepository.Instance;
var widgetbox = repo.DigitalBanking.widgetbox;
var option1 = repo.DigitalBanking.Payees.option;

repo.DigitalBanking.widgetbox.Click(); <-this is clicking the drop down box

option1.Element.SetAttributeValue("label",widgetname); <-here i want to click on the innertext or label of option provided by the user

2018_12_12_13_38_48_BottomLineII_Ranorex_Studio_Administrator_.png (13.11 KiB) Viewed 1178 times
there are 15 widgets so i have 15 test cases. i will use the code in all the test cases to add relevant widget.

please help.
(49.86 KiB) Downloaded 81 times

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

Re: Code for Adding from the dropdown list

Post by odklizec » Thu Dec 13, 2018 8:46 am


I see you are using Chrome. And the problem is, that Chrome (from all browsers) does not have the individual select list options recognizable by Ranorex (any UI TA tool). It's because of the way Chrome creates the select list. So, there is unfortunately no use for standard "click selectbox -> click desired select option" sequence in Chrome.

What you can do, is to create a repo item pointing to the select tag of your choice, which should have xpath like this (based of the provided snapshot):
Now you simple add 'Key Sequence' action, targeted to the above select tag. And then add a variable, containing the value you want to select. And that's all. You don't even have to use code :D True, it's not a typical user-like action, but at least this technique works across all browsers! Courtesy of forum member krstcs ;)
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

Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Re: Code for Adding from the dropdown list

Post by maamer » Thu Dec 13, 2018 7:45 pm

thank you sir.