How to select a Option in a Select tag element (Dropdown)

Best practices, code snippets for common functionality, examples, and guidelines.
uthirukovaluru
Posts: 1
Joined: Wed May 14, 2014 2:29 pm

Re: How to select a Option in a Select tag element (Dropdown)

Post by uthirukovaluru » Thu May 15, 2014 3:42 pm

I still believe this is a ongoing topic for most of the people for those whom might be started working on Ranorex recently. Important bit is, especially the code starts from 'inner:' to 'goto inner;' lines. Try with this let me know your feedbacks.

Code: Select all

string strDomain = "/dom[@domain~'"+GlobalVariables.strURLPath+"']"
string strText = "//select[@name='"+strDropDownFieldName+"']";
		for (int i=1;i<=20;i++)
		{
			strText = "/?"+strText;
			RxPath strDropDownPath = strDomain+strText+"/option[@innertext='"+strDropDownFieldValue+"']";
			try
			{
				if (Validate.Exists(strDropDownPath,500,"Checking Object exists '"+strDropDownFieldName+"'",new Validate.Options(ReportLevel.Debug)))
				{
					Ranorex.OptionTag objOption = strDomain+strText+"/option[@innertext='"+strDropDownFieldValue+"']";
					int ItemIndex = objOption.Element.ChildIndex;
					Ranorex.SelectTag objSelect = strDomain+strText;
					if(!objOption.Selected)
					{
					inner:
						objSelect.PressKeys(strDropDownFieldValue);//.Substring(0,1));
    					Delay.Seconds(2);
						objOption = strDomain+strText+"/option[@innertext='"+strDropDownFieldValue+"']";
						if(!objOption.Selected)
							goto inner;							
					}
					break;
				}
			}
			catch(Exception ex)
			{
		       	if(i==20)
		       		Report.Failure("No Object Found either with logical name of it or with as it is name for - "+strDropDownFieldName,ex.Message);							
			}
		}