I’m having trouble selecting a list that is mixed with javascript. The original code on the page is 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 the JS file loads, it modifies the List and when I view Generated Source, I get this:
<div tabindex="0" style="-moz-user-select: none;" role="listbox" title="Fruit" class="fruit-box k-select">Select..</div>
And WatiN cannot find the listbox anymore..
I tried:
browser.Element(Find.ById("Fruit")).Focus();
browser.Element(Find.ById("Fruit")).Click();
but that didn’t trigger the dropdown list to go down. Then I tried to request the page with GoToNoWait(); and then use a loop to find the list, before JS is loaded, that modifies it:
while (browser.SelectLists.Count <= 0)
{
Thread.Sleep(100); // wait until the first option list is loaded
}
foreach (WatiN.Core.SelectList a in brower.SelectLists)
{
if (a.IdOrName == "Fruit")
{
a.SelectByValue("val_1");
}
}
I can see the list showing up normal in browser (not JS) at first, but the loop hangs while the page is loading and JS gets loaded before foreach loop gets a chance to get executed..
My only solution is 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 I need to have firefox window in focus, otherwise the keystrokes get sent to whatever application I have currently open which doesn’t work for me.
Is there a way to select the option list, before JS is added to it? OR is there a way to use SendKeys and point it to specific application instead of currently focused one? Thank you!
I am assuming that a set of LI items get generated by the javascript which can then be selected on the UI. If that is true, you might want to try this