Friday, June 8, 2012

Selenium: Testing auto complete fields

Selenium's "type" command does not trigger auto complete feature to give suggestion. We can use "typeKeys" method to simulate auto complete. Here is the sample code for this:
public static void inputTextInAutocompleteField(String testField, String testValue) 
{
        try {
                selenium.type(testField, testValue);
                selenium.typeKeys(testField," \b") ;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Here we are first entering value in the text field, then using selenium's 'typeKeys' method to press 'space' character and then 'backspace' (\b) character.

No comments: