Search code examples
watinautocompleteextender

How to click on an AutoCompleteExtender with Watin


For my acceptance testing I'm writing text into the auto complete extender and I need to click on the populated list.

In order to populate the list I have to use AppendText instead of TypeText, otherwise the textbox looses focus before the list is populated.

Now my problem is when I try to click on the populated list. I've tried searching the UL element and clicking on it; but it's not firing the click event on the list.

Then I tried to search the list by tagname and value:

Element element = Browser.Element(Find.By("tagname", "li") && Find.ByValue("lookupString"));

but it's not finding it, has anyone been able to do what I'm trying to do?


Solution

  • The shorter version of that is:

    string lookupString = "string in list";
    Element list = Browser.Element("li", Find.ByText(new Regex(lookupString)));
    list.MouseDown();
    

    Regexs will do a partial match so you don't need to specify .* either side and use string.Format. This assumes however that the lookupString doesn't contain any characters special to Regexs, they'd need to be escaped.