I have a test case that requires typing in a partial value into an ajax based textfield and verifying the list has the expected content. If it does, select the content. Any idea how to make this work?
Your question is slightly ambigious.
Most browsers keep a value cache that is based on the name of the field: This is the value that is being suggested as autocompletion by your browser even though you may never have visited the site before. This feature is non-standard across all browsers, and there's going to be no standard way for selenium to detect/analyze this. You can still do it, but you'll have to make javascript functions that determine the values yourself. Then you can use "eval" in selenium to execute these functions. I have not seen any js libraries that can tell you these values in a cross-browser compatible way.
The other alternative is that you use ajax to do a server-side submit of the partially entered value. In this case it's just a matter of typing the values into the textbox and asserting that the expected values turn up. Normally the autocomplete suggestions show up in some layer on the client side.
I'd do this as follows:
type
to enter the value in the text field.waitForTextPresent
orverifyTextPresent
to check the autocomplete contentclick
ormouseDown
to click on the item in the autocomplete list
The trick is going to be making the final click
be just in the right place. You should be able to use an XPath expression that searches for the text you're expecting to find it.
The type command may not be enough to trigger the autocomplete. Dave Webb's suggestions are otherwise spot on. My only addition would be that you might need the typeKeys command, which causes slightly different JavaScript events to be fired, which may be more likely to trigger the autocomplete widget.
Shameless plug: if you were a BrowserMob load testing customer, you could get free answers to these questions from our support team ;)
I found I needed to do a focus on the field before doing typeKeys to get it to work.
I recently wrote a HOWTO on this very topic - using Selenium to test an AJAX-driven JQuery autocomplete menu:
Cheers, Jason