Failing to Click on Option in Select List

Ranorex Spy, Recorder, and Studio.
AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Failing to Click on Option in Select List

Post by AccidentReport » Thu Jan 30, 2014 12:21 pm

Hello.

I am having an issue with Ranorex not clicking on an object and cannot understand what is wrong.

The code below is pretty much a direct port of code from another module I have written which reads the options in a form select list, locates the one matching the required value and clicks on it. The only difference is that the other module is looking at a pop up window and this one is looking in the main browser.

The general loop of this works and it will go through each option in the list and find the correct one (i've put breakes in and it is on the right option), however when it tries to click instead of clicking in the centre of the option (like the other code does) it clicks in the top left-hand corner of the screen. It seems to have no idea where the option is to click on it.

Any ideas or am I having a moment?! :?

Code: Select all

        	
SelectTag myDNList = repo.BTIA2.Ctl00CphMainLstService;
IList<Ranorex.OptionTag> myDNOptions = myDNList.FindDescendants<Ranorex.OptionTag>();
int myDNCount = myDNOptions.Count;
bool myDNFound = false;
dialledNumber = "01234567890";

foreach (Ranorex.OptionTag thisDNOption in myDNOptions) {
	if (thisDNOption.InnerText.Contains(dialledNumber)) {
		myDNFound = true;
		thisDNOption.Click();
		break;
	}
}

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

Re: Failing to Click on Option in Select List

Post by krstcs » Thu Jan 30, 2014 2:29 pm

This is a known issue with drop-down lists with several browsers (most notably Chrome).

Chrome does not present the actual drop-down list to the UI so Ranorex has no way to know where to click, so it clicks at screen location 0,0. There is nothing Ranorex can do about it.

You will have more luck using a keyboard "Down" action until you find the option you want.

See my post in this thread: http://www.ranorex.com/forum/cant-click ... t5683.html

It contains the code I use to do this for all browsers (since they are all inconsistent in this respect).
Shortcuts usually aren't...

AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Re: Failing to Click on Option in Select List

Post by AccidentReport » Thu Jan 30, 2014 2:42 pm

I'm using IE. As for the issue, it works correctly on a drop-down (it's not actually a drop-down as such ad it shows as a scrollable list instead but it is the same) on a smaller window that is "born" from the main window but not on the main window itself. I'd understand if it didn't work at all but it makes not sense that the same function does not work on what are essentially the same type of object!

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

Re: Failing to Click on Option in Select List

Post by krstcs » Thu Jan 30, 2014 2:56 pm

As I said, Chrome is the big offender, but I have seen issues with other browsers as well.

And the problem is with <Select><Option/><Option/></Select> tags, not just drop-downs, so I should have been more specific.

A drop-down is essentially a new, border-less window that gets created right under the <Select> element when you click the <Select> tag's field or arrow button, so your case is essentially the same thing type of thing, with a new window. That new window is not fully presented by the browser.

But, without seeing your application or a snapshot of it, this is just conjecture on my part based on the code you posted.

Again, I would try using the keyboard method as it is much more consistent and reliable on all browsers. But that's just my opinion, take it for what it's worth. :D
Shortcuts usually aren't...

AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Re: Failing to Click on Option in Select List

Post by AccidentReport » Thu Jan 30, 2014 3:28 pm

To be honest I'd already worked out what I call the 'DIRRTY Solution' to the issue which is a counter and the down arrow. Not how I want to do it as it's not really precise but it will do in a pinch. Just weird how different windows of IE behave differently with Ranorex!

Oh well, seem to be my week for finding existing bugs that have no date on a fix! :(

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

Re: Failing to Click on Option in Select List

Post by Support Team » Tue Feb 11, 2014 5:45 pm

Hi AccidentReport,

Try this solution to select an OptionTag in a DropDownlist

Code: Select all

public void SetOptionInList (string argument1)
{
int counter;
IList<OptionTag> optionlist = ***.FindDescendants<OptionTag>(); //Creates an Ilist with all Elements in Dropdown
counter = optionlist.Count; //Counter for Listelements
Report.Info("List","Elements: "+counter); //Writes to log how many items in list are
foreach(OptionTag option in optionlist)
{
if(option.InnerText==argument1) //Compares the value of Option.InnerText with the parameter 'argument1'
{
Report.Info("Values",argument1+"is in List");
option.Selected=true; //marks the desired element 
break;//exits the foreach loop
}//End If
}//End foreach
}//End SetOptionInList(string argument1)
Instead of clicking the Element in the dropdown I would prefer to set the selected attribute =true.
Create an IList<OptionTag> with the OptionTags from the DropDownList
Loop every item in this list with a foreach
If the desired element is in the list, set the selected attribute to true.
Break to exit the foreach

Regards,
Markus
.
Image

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

Re: Failing to Click on Option in Select List

Post by krstcs » Tue Feb 11, 2014 5:56 pm

Markus' solution will also work, but I would caution that it might have unintended side-effects depending on how your system under test fires the events surrounding the selection of the item. Sometimes those events are not fired correctly if you just set the values behind the scenes.

I would strongly recommend that keyboard manipulation is the most accurate and reliable way of doing this.
Shortcuts usually aren't...