select option in <select? box on web page ... noob

Ask general questions here.
sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

select option in <select? box on web page ... noob

Post by sstowe » Mon Jun 11, 2018 9:40 pm

I have not used Ranorex in a few years, so bear with me, please. I know this is basic. I have a <select> in my repository. I want to write some user code or test module steps (don't care) to select one of the options that becomes visible when the <select> is clicked by text. All the examples I am finding are not using an existing repository item... so I am not learning from the examples I see. This is pretty basic. Thanks!

S

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

Re: select option in <select? box on web page ... noob

Post by odklizec » Tue Jun 12, 2018 7:36 am

Hi,

Item selection in "select" box heavily depends on the implementation of select box in question. Could you please provide a snapshot of the select box or even better, a working HTML sample (e.g. using this page https://www.w3schools.com/tags/tryit.as ... tml_select)?
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

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: select option in <select? box on web page ... noob

Post by sstowe » Tue Jun 12, 2018 3:59 pm

Spanshot I will try a working sample now.
Attachments
widgetselect.rxsnp
(55.63 KiB) Downloaded 9 times

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

Re: select option in <select? box on web page ... noob

Post by odklizec » Wed Jun 13, 2018 8:01 am

Hi,

OK, in my opinion, the easiest approach is to click the select box (to expanded it) and then click the option you want to select. For this, you need to create two repository elements. First pointing to select box, the second one to the option you want to click. And because you most probably don't want to create a repo item for each option in the select list, you should variabilize it.

So the xpath for select element should be like this:
//div[#'SMBHOME']//form[@name='widget-injector-form']/select[@name='widget-injector']
and the xpath for select option like this:
//div[#'SMBHOME']//form[@name='widget-injector-form']/select[@name='widget-injector']/option[@innertext=$optionString]
Then drag&drop first repo element (select item) to the recording of your choice and from the appeared menu select Mouse click action. Then D&D second element and make sure the variable is filled with select option you want to select (via data connector or test case/smart folder parameter). Now of you run your test, it should expand the select element and then pick the option you specified in variable. Hope this helps?
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

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: select option in <select? box on web page ... noob

Post by sstowe » Wed Jun 13, 2018 2:01 pm

Ok, by way of research I tried something like this-ish. I did a recording of clicking the select, then the option. The option was added to the repo. When I played it back, the test ran successfully, but no click occurred on the application.

Thanks

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

Re: select option in <select? box on web page ... noob

Post by odklizec » Wed Jun 13, 2018 2:08 pm

Hi,

Unfortunately, it's too hard/impossible to tell what's wrong without seeing, at very least, the problematic recording with included repository (and snapshot). What you can try is to enable "Turbo" mode for given recording, which may eliminate some click-related errors, caused by too slow mouse movement. This kind of problems usually happens in tests started on virtual machine (accessed via RD). But it's worth a try also in your case?
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

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: select option in <select? box on web page ... noob

Post by sstowe » Wed Jun 13, 2018 7:50 pm

Alrighty, I got confused as I tried different things. When I did a recording, the step that was created was SetValue, not the 2 subsequent clicks like I thought. The select box is like

<select name="MyName">
<option value="-1">Add My Thing</option>
<option value="stupidrandomcode">Thing To Add</option>

....

When I recorded, the SetValue was setting the value to -1, thus my play back looked like it was not working. Ok, ok, this very well could have been operator (me) error. But when I SetValue to stupidrandomcode, the correct selection is made.

Solution! Thanks for your help!

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: select option in <select? box on web page ... noob

Post by sstowe » Wed Jun 13, 2018 7:56 pm

Hmmmm, is there any chance I have discovered a bug in the recorder code? I tried to record this again and definitely selected an option item. I got value = -1 as my value in the recorded step. No skin off my nose since I know what to do. But I wondered. Thanks.

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

Re: select option in <select? box on web page ... noob

Post by odklizec » Wed Jun 13, 2018 8:24 pm

Hi,

No, it’s not a bug. The thing is, that recorder prefers to use SetValue action for combo boxes. And the problem is, that in case of your Select box, there are different TagValues, which are not visible for user, and Text values, which are actually visible in select box. But because TagValue is prioritised for SetValue action, recorder picks -1, which is the TagValue for item you have selected during recording. I believe you selected the first item in the list? If you select different item, the recorded TagValue will be something else than -1.

To be honest, I would replace recorded SetValue action with mouse click actions. SetValue is not exactly user-based approach and may not trigger certain mouse-based events, eventually attached to the select box in question. Picking select box element with mouse is simply more appropriate way of selecting items in combo boxes.
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

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: select option in <select? box on web page ... noob

Post by sstowe » Wed Jun 13, 2018 9:19 pm

In answer to this:

I believe you selected the first item in the list? If you select different item, the recorded TagValue will be something else than -1.

The answer is no, I selected a different item.

But I will try your click method instead. Thanks.