Selenium how to select an object by class

aron picture aron · Apr 4, 2011 · Viewed 48.6k times · Source

I have a web page with a form and has a field that uses the jquery autocomplete function.

enter image description here

This is how the HTML renders after a user name returns 1 or more results.

However I cannot figure out how to make Selenium "click" a result.

enter image description here

Can I do a jQuery type of selector. e.g.

$(".ul.ui-autocomplete li:first a")

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Apr 4, 2011

Use XPath selector in Selenium:

xpath=//li[contains(@class, 'ui-autocomplete')]/li[1]/a

not checked, might require some corrections.