Potential BUG?: <select> dropdown not recognized as HTML

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

Potential BUG?: <select> dropdown not recognized as HTML

Post by krstcs » Wed Sep 04, 2013 8:19 pm

I am currently working on our eCommerce site, which is HTML.

We have several drop-downs that are coded as:

Code: Select all

<select ...>
  <option value="1" ...>Item1</option>
  <option value="2" ...>Item2</option>
  ...
</select>
Ranorex can see the full structure correctly, if you spy the select tag, but when you click the drop-down and the system displays the child list, it is seen by Spy and Ranorex as a new "Container" object and is not under the structure of the website. (I am having to use Instant Tracking as the drop-down has no delay on close.)

So, even though I can see the HTML structure when I spy the <select>, the <option> elements are not seen if I click on the <select> and instead, a new Container object is seen, which in FF and Chrome does not have any child list items, but in IE it does.

I do not believe this is a problem with the site or the browsers since the site structure is seen correctly when Spy is used on the select object, and all of the browsers show a similar issue. It seems to be a problem with Ranorex interpreting the <select>'s <option> list container incorrectly.

I am attaching a snapshot of the actual elements. I cannot get a snapshot of the "Container" object due to the auto-close of the list.
Attachments
Store Selection Drop-down.rxsnp
(270.23 KiB) Downloaded 214 times
Shortcuts usually aren't...

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by Support Team » Thu Sep 05, 2013 4:01 pm

Hello,

Unfortunately, the HTML Select option tag is not fully supported by all browsers.
IE handles the Drop Down list differently than other browsers.
Therefore, you are able to see the list entries in IE.

It's recommended to track the Select tag (do not open list) with Spy.
Then, you would need to use each Option tag within the Select tag.

Please take a look at the posts below:
http://www.ranorex.com/forum/selecting- ... t2695.html
http://www.ranorex.com/forum/how-to-sel ... -t998.html

Regards,
Markus (T)
.
Image

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by krstcs » Thu Sep 05, 2013 7:05 pm

OK, I think this has to do with Chrome's issues with drop-downs (compounded with my missing a separate issue in my test).

So, the question still remains as to how to automate, especially data-driven, a drop-down list selection when there is an event associated with it??

I have to be able to mouse-click the optiontag, keyboard input in this case is not reliable because options might move around. I am looking at a procedural approach that might work, but it's a hack.

This works in FF and IE. So what is Chrome doing that is different, and why can't Ranorex detect it?

I know you said they don't give out the location of the drop-down, but isn't there some way to find it? They have to change something on screen to get it to display, so why can't Ranorex pick that up? The DOM structure HAS to be pushed out to the screen for it to be rendered. There's only so much obfuscation Google can do...

Thanks for the help!
Shortcuts usually aren't...

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by Support Team » Fri Sep 06, 2013 3:13 pm

Hello,

Unfortunately, Chrome don't divulge any information about the option tag's position to Ranorex.
That's why we don't get any ListItems below the container element.
To select a specific option tag in your select tag you could use the following code
SelectTag someSelectTag = "/dom[@caption='Tryit Editor v1.8']//iframe[#'iframeResult']/?/?/select";
OptionTag optTag = someSelectTag.FindSingle(".//option[@value='audi']");
optTag.Selected = true;;
The sample page is http://www.w3schools.com/tags/tryit.asp ... tml_option
The code above works in browsers: IE, Chrome and Firefox.

If you need to simulate user input, then you could also focus the select tag and press left/right arrow key until you reach the correct value.

Regards,
Markus (T)
.
Image

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by krstcs » Fri Sep 06, 2013 9:05 pm

Thanks Markus.

Unfortunately it took a bit more work than it should have, so I will share what I did so others can get benefit from it...

I add the following code inside the Program.cs file, inside the Program class. I can then call it from any module in that project.

The modules that do my select actions would click the selecttag and then have a usercode method that calls this with the specified selecttag and desired optiontag.

If the browser is Chrome, it figures out which element is selected and which element is needed, then presses the UP or DOWN keys the number of times required and then presses ENTER. This will fire the event needed.

If the browser is NOT Chrome, it will just mouse click the optiontag.

NOTE: This assumes that the select tag has already been clicked.

Code: Select all

        public static WebDocument GetRootDOM(Element thisElement) {
        	if (thisElement.PreferredCapability.DisplayName.ToLower().Equals("webdocument")) {
        		return thisElement;
        	}
        	
        	return Program.GetRootDOM(thisElement.Parent);
        }
        
        public static void SelectOption(SelectTag selectTag, OptionTag optionTag) {
        	string browser = GetRootDOM(selectTag).BrowserName;
        	
        	switch (browser) {
        		case "Chrome":
        			SelectOption_CHROME(selectTag, optionTag);
        			break;
        		default:
        			SelectOption_Normal(optionTag);
        			break;
        	}
        }
        public static void SelectOption_Normal(OptionTag optionTag) {
        	Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item '" + optionTag.GetPath().ToResolvedString() + "' at Center.");
        	optionTag.Click();
        }
        
        public static void SelectOption_CHROME(SelectTag selectTag, OptionTag optionTag) {
        	string selectedTagValue = selectTag.TagValue;
        	string desiredTagValue = optionTag.TagValue;
        	
        	OptionTag selectedOptionTag = selectTag.Find<OptionTag>(".//option[@TagValue='" + selectedTagValue + "']")[0];
        	
        	//List<OptionTag> options = new List<OptionTag>(selectTag.Find<OptionTag>(".//option"));
        	
        	List<string> options = new List<string>();
        	
        	foreach (OptionTag ot in selectTag.Find<OptionTag>(".//option")) {
        		options.Add(ot.TagValue);
        	}
        	
        	int selectedIndex = options.IndexOf(selectedOptionTag.TagValue);
        	int desiredIndex = options.IndexOf(optionTag.TagValue);
			
        	Keyboard.PrepareFocus(selectTag);

        	if (desiredIndex < selectedIndex) {
        		for (int i = desiredIndex; i < selectedIndex; i++) {
        			//up
        			Report.Log(ReportLevel.Info, "Keyboard", "Key 'Up' Press with focus on '" + selectTag.GetPath() + "'.");
        			Keyboard.Press(System.Windows.Forms.Keys.Up, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
        		}
        	} else if (selectedIndex < desiredIndex) {
        		for (int i = selectedIndex; i < desiredIndex; i++) {
        			//down
            		Report.Log(ReportLevel.Info, "Keyboard", "Key 'Down' Press with focus on '" + selectTag.GetPath() + "'.");
         			Keyboard.Press(System.Windows.Forms.Keys.Down, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
       			}
        	}
        	
            Report.Log(ReportLevel.Info, "Keyboard", "Key 'Enter' Press with focus on '" + selectTag.GetPath() + "'.");
        	Keyboard.Press(System.Windows.Forms.Keys.Enter, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
        }
    }
Do you guys know if there is a bug tracker item in Chrome for this issue of not providing UIAutomation info for option drop-downs? I can't believe that this isn't just an over-looked issue for them. Most of the other elements work correctly with Chrome.
Shortcuts usually aren't...

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by Support Team » Tue Sep 10, 2013 4:31 pm

Hello,

Thank you for providing your solution.
Unfortunately I don't know if there is a bug tracker item for this issue.

Regards,
Bernhard
.
Image

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by lucian.teodorescu » Mon Jul 27, 2015 4:45 pm

UP!

Chrome's dropdown elements are still NOT detected! All that Spy finds is a single adapter, directly linked to the hosting machine (absolute path: "/container[@caption='dropdown']").

Many thanks krstcs for your workaround! Works like charm!
Lucian Teodorescu
NetSun Software

NewLearner
Posts: 29
Joined: Wed Jan 15, 2014 3:32 pm

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by NewLearner » Wed Aug 26, 2015 1:38 pm

I think...This is issue still there, I'm using Ranorex5.4 but i can't select dropdown in chrome browser..

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

Re: Potential BUG?: <select> dropdown not recognized as HTML

Post by krstcs » Wed Aug 26, 2015 2:58 pm

Unfortunately, this is not a Ranorex issue, but a Chrome issue. Chrome does not present the contents of drop-down boxes to the /DOM. Your best bet is to use the work-around I described above in order to make it consistent in all browsers.
Shortcuts usually aren't...