c# - Watin, selecting html option list, generated by Javascript -
i'm having trouble selecting list mixed javascript. original code on page this:
<select id="list_1" name="list_1"> <option value="">select..</option> <option value="val_1" >orange</option> <option value="val_2" >apple</option> <option value="val_3" >peach</option> </select>
but when js file loads, modifies list , when view generated source, this:
<div tabindex="0" style="-moz-user-select: none;" role="listbox" title="fruit" class="fruit-box k-select">select..</div>
and watin cannot find listbox anymore..
i tried:
browser.element(find.byid("fruit")).focus(); browser.element(find.byid("fruit")).click();
but didn't trigger dropdown list go down. tried request page gotonowait(); , use loop find list, before js loaded, modifies it:
while (browser.selectlists.count <= 0) { thread.sleep(100); // wait until first option list loaded } foreach (watin.core.selectlist in brower.selectlists) { if (a.idorname == "fruit") { a.selectbyvalue("val_1"); } }
i can see list showing normal in browser (not js) @ first, loop hangs while page loading , js gets loaded before foreach loop gets chance executed..
my solution this:
browser.div(find.bytitle("fruit")).focus(); browser.div(find.bytitle("fruit")).click(); browser.div(find.bytitle("fruit")).fireevent("onclick"); sendkeys.sendwait("{down}"); sendkeys.sendwait("{down}"); sendkeys.sendwait("{enter}");
but when using sendkeys need have firefox window in focus, otherwise keystrokes sent whatever application have open doesn't work me.
is there way select option list, before js added it? or there way use sendkeys , point specific application instead of focused one? thank you!
i assuming set of li items generated javascript can selected on ui. if true, might want try
div fruitdiv = browserinstance.div(find.bytitle("fruit")); fruitdiv.click(); fruitdiv.keydown(); watin.core.list autocompletelist = (watin.core.list)fruitdiv.nextsibling; // or whatever relation autocompletelist.waituntilexists(); string value = "value select in list"; listitem datavaluelistitem = autocompletelist.listitem(find.bytext(new regex("^" + value + "*"))); datavaluelistitem.mousedown(); fruitdiv.waitforcomplete(); browserinstance.waitforcomplete();
Comments
Post a Comment