/// <summary> /// Clicks or sets a web page select tag option. /// </summary> /// <param name="pathToDOM">Ranorex.Core.Repository.RepoGenBaseFolder.BaseBath of a web page DOM.</param> /// <param name="selecttag">Ranorex.SelectTag of a web page select tag.</param> /// <param name="option">option to select in select tag.</param> public static void ChooseSelectTagOption(string pathToDOM, Ranorex.SelectTag selecttag, string option) { WebDocument domWebDocument = pathToDOM; string selectTagValueForOption = null; switch (domWebDocument.BrowserName) { case "Chrome": case "Safari": case "Mozilla": //Using Chrome and Safari select tag with mouse problematic. So select using keyboard. //For Mozilla, OptionTag.Visible does not return the correct value for an option tag that is not visible. So select using keyboard. selectTagValueForOption = FindSelectTagValueForOption(selecttag, option); SelectTagValueWithKeyboard(selecttag, selectTagValueForOption); break; case "IE": //Click option if visible after clicking select tag. String itemToClickRxPath = String.Format("/container[@caption='selectbox']/listitem[@accessiblename='{0}']",option); selecttag.Focus(); selecttag.Click(); ListItem itemToClick; try { itemToClick = itemToClickRxPath; } catch (Exception e) { throw new ArgumentException(string.Format("Unable to find option {0} in SelectTag {1}. Exception:{2}", option, selecttag.Name,e), "option"); } if (itemToClick.Visible) { itemToClick.Click(); break; } //If not visible, select using keyboard. selectTagValueForOption = FindSelectTagValueForOption(selecttag, option); //Close Select Tag box. selecttag.Click(); SelectTagValueWithKeyboard(selecttag, selectTagValueForOption); break; default: throw new Exception(String.Format("Browser not supported: {0}", domWebDocument.BrowserName)); } }