Select option.selected = true is not going through

Ask general questions here.
fimo420
Posts: 55
Joined: Wed Jun 20, 2012 9:49 am

Select option.selected = true is not going through

Post by fimo420 » Fri Jul 12, 2013 9:45 am

Hi,

I'm trying to do a select option from an webpage but its not going through.
I used the code below which someone from forum posted in another topic. I can see that the changes goes through, but its not used, hard to explain :(.
I can see that the selections is done if i debug/pause after the selection, but when it goes to nextpage its supposed to use that selected option, but there its wrong, it goes back to orginal value. Its like it never clicked.

Code: Select all

SelectTag someSelectTag = "yourSelectTagPath";   
IList<OptionTag> list = someSelectTag.FindChildren<OptionTag>();   
  
             foreach(OptionTag opTag in list){   
                    // Output of all Option Tags   
                    Report.Info("OptionTag: "+opTag.InnerText);   
                    // Selection of yourTag   
                    if(opTag.InnerText=="YourTag")   
                        opTag.Selected= true;   
}  
I mean i can get this working through different way, like first clicking on the object then pressing down arrow until i see my option and then press enter. But thats a bad way to code and if the select option list is very long like 100 options its a pain :(.

Anyone got any suggestions, please let me know, would really appreciate it!

Br,
Feroz

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Select option.selected = true is not going through

Post by krstcs » Fri Jul 12, 2013 1:46 pm

I would guess that you need to actually do a *.Click() on the option element instead of trying to set the value because your developers have an event firing at some point in the background that you are not actually setting with the *.Selected = true; statement.

The problem with directly setting values or doing Invokes is that they do not always trigger the events that cause actual things to happen.

I have found that using Mouse->Click and Key->Shortcut/Sequence is better most of the time because it actually exercises the systems the way a human would, triggering the events, etc.

The only issues with this are:
1. You will not be able to LOCK the computer while a test is running.
2. You will not be able to do anything else on the computer while a test is running.

The solution is to run tests on a separate system. I use virtual machines as they are easier to manage.
Shortcuts usually aren't...

fimo420
Posts: 55
Joined: Wed Jun 20, 2012 9:49 am

Re: Select option.selected = true is not going through

Post by fimo420 » Sat Jul 13, 2013 10:24 am

Hi

i guess your right, cause it works fine when doing click events or with keyboard sequences (enter).
But then the problem arrives how to do this on big lists?
cause i have one select box with like i dont know all the currencys in the world (a lot ), i mean with select option its pretty easy it but since it doesnt click it nothing happens :(
I'll try to find the option tag on monday and see if that works, then try to click it.

But if anyone else already have a solution for this issue please let me know :)

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Select option.selected = true is not going through

Post by krstcs » Mon Jul 15, 2013 1:42 pm

You could try to do an "EnsureVisible()" on the element before you "Click()" it. Sometimes that works (although I have found that it doesn't with some JavaScript libraries).

Otherwise you would need to create a routine that scrolls down (or up) until the option you want is in view and then click it.
Shortcuts usually aren't...

fimo420
Posts: 55
Joined: Wed Jun 20, 2012 9:49 am

Re: Select option.selected = true is not going through

Post by fimo420 » Mon Jul 15, 2013 2:19 pm

EnsureVisible() doesnt work.

ex, list has 100 items
if i scroll to 50 -> all between 30-60 is shown as visible in ranorex spy but it should only be all 40-50 visible
so, lets say i wan click item 80, i made a page down scroll method, that scrolls down until item is visible.
so it will do page down until 60 then say that item is visible but when its not and click on 80 but it wont actually be selected on the list, instead its clicking on something else.

Very weird