Tuesday, December 06, 2011

Testing autocomplete fields with Selenium

Sometimes we face some  editboxes in the application that shows suggestions while you type. In some of the application you need to choose from that suggestions only to filled the edit box else it won't consider . 
If you will simple type in the editbox using type method it won't give you any suggestion coz it works on keyevent so to see the suggestion you will require to use the keyPressNative() method.

While typing TEST11 in the autocomplete field 
If you 'll use simply type() method,
  1. selenium.type("locator-of-the-autosuggest-element""TEST11");
it willn't work.

You need to use like the following:
  1. selenium.focus("locator-of-the-autosuggest-element");
  2. selenium.keyPressNative("32"); //space
  3. selenium.keyDownNative("16"); //SHIFT ON
  4. selenium.keyPressNative("84"); //T
  5. selenium.keyPressNative("69"); //E
  6. selenium.keyPressNative("83"); //S
  7. selenium.keyPressNative("84"); //T
  8. selenium.keyUpNative("16"); // SHIFT OFF
  9. selenium.keyPressNative("49"); //1
  10. selenium.keyPressNative("49"); //1
Or,simply you can use like following:
  1. selenium.type("locator-of-the-autosuggest-element""TEST1");
  2. selenium.focus("locator-of-the-autosuggest-element");
  3. selenium.keyPressNative("49"); //1

No comments:

Post a Comment