Selecting option from selectlist using watin issue

243 views Asked by At

I have a selectlist with the HTML:

<select style="background-color: rgb(255, 255, 255);" id="advFindE_fieldListFLDCTL" class="ms-crm-SelectBox" Sort="ascending" defaultSelected="-1">
<optgroup id="fld" label="Fields">
<option title="Case" value="il_caseid" datatype="lookup" namemaxlength="200" nameattr="il_caseidname" lookupstyle="single" lookuptypenames="il_protectionworksheet:10093:Protection Worksheet" lookuptypes="10093">Case</option>
<option title="Created By" value="createdby" datatype="lookup" namemaxlength="320" nameattr="createdbyname" lookupstyle="single" lookuptypenames="systemuser:8:User" lookuptypes="8">Created By</option>
...
<optgroup id="ent" label="Related">
...
</optgroup></select>

And for the life of me I just can't select the "created by" option via watin. I'm not sure if its because of the optgroup elements or what. I've tried almost everyway I can think of such as:

advancedFindWindow.Frame(CRMConstants.contentIFrame).SelectList("advFindE_fieldListFLDCTL").Option("Created By").Select();

or

advancedFindWindow.Frame(CRMConstants.contentIFrame).SelectList("advFindE_fieldListFLDCTL").Option("Created By").Click();

or

    advancedFindWindow.Frame(CRMConstants.contentIFrame).Div("advFindE_fieldListFLDLBL").Focus();
advancedFindWindow.Frame(CRMConstants.contentIFrame).Div("advFindE_fieldListFLDLBL").Click();
Thread.Sleep(250);
advancedFindWindow.Frame(CRMConstants.contentIFrame).SelectList("advFindE_fieldListFLDCTL").Focus();
advancedFindWindow.Frame(CRMConstants.contentIFrame).SelectList("advFindE_fieldListFLDCTL").Click();
SendKeys.SendWait("Created By");
Thread.Sleep(1000);
SendKeys.SendWait("{ENTER}");

However none of these seem to work. The last attempt does select an option but it selects a completely different option for some reason. I'm completely clueless. Any ideas would be helpful.

1

There are 1 answers

0
ProgrammerV5 On

It will be much easier for you if you select the items by value as those tend to change much less than the text itself. The change is rather simple:

advancedFindWindow.Frame(CRMConstants.contentIFrame).SelectList("advFindE_fieldListFLDCTL").SelectByValue("createdby");

If this is not fixing your problem, please indicate the page you are trying to use and I'll create the code for you to select the correct option.