keyDown action implemetation for JQuery Autocomplete box

559 views
Skip to first unread message

B Chandra

unread,
Jul 24, 2012, 3:43:42 AM7/24/12
to webd...@googlegroups.com
Can anyone give demo using keydown action event for jquery autocomplete?
When I enter input string into input box, all possible dynamic results are displayed in autocomplete list.
I have to select particular result in list?
I can not use Xpath of exact result, because it is changing dynamically.

Eran Mes

unread,
Jul 24, 2012, 5:12:02 AM7/24/12
to webd...@googlegroups.com
The keyDown action is just for modifier keys. It sounds like you'd want to send a keypress, wait until an autocomplete list appears, then send Keys.DOWN several times to pick an option.
See this discussion: https://groups.google.com/forum/#!topic/selenium-users/0hOGu5La1nQ

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/m9SJJU5eEHkJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

B Chandra

unread,
Jul 25, 2012, 12:56:16 AM7/25/12
to eran...@gmail.com, webd...@googlegroups.com
Hello Eron,
Good Morning.!

I gone through discussion. I got it, but the main problem is I am still unable to enter autocomplete box showing list of possible results.
First thing to know is I have to wait after each letter is provided in input box and I implemented this in following way--
String loc_nm= "Nagpur";
for(int i=0;i<loc_nm.length();i++)
{
searchBox.sendKeys(Character.toString(loc_nm.charAt(i)));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Now I am getting possible list as shown in second screen "list_of_results".
I am providing few snapshots of webpage.First screen"autocomplete_box" shows the div & class of autocomplete_box in which all results are contained. Second screen "list_of_results" shows list of results and third screen "select_result" shows result which is selected.

Main problem is I am unable to enter autocomplete_box using any of ID, cssSelector and ID. Then I have to go through whole list starting from first result. And here also I am unable to enter box and use key down action or mouse over action. Then I have to select particular result as shown in third screen.

I have provided all screens with their HTML code.Can I get help to sort out my problem? I am also unable to use xpath of element due to dynamic ID genarated.
First problem is how to locate web elements according to attachment order by using any element locator(ID,xpath,cssSelector etc).
Second problem is use keyDown or Mouseover action (I don't have any other option)

--

Best regards,

B Chandra

autocomplete_box.jpg
list_of_results.jpg
select_result.jpg

Eran Mes

unread,
Aug 2, 2012, 6:58:54 AM8/2/12
to B Chandra, webd...@googlegroups.com
The recommended way is to add proper IDs to the element you want to locate.
Alternatively, call sendKeys(Keys.DOWN) on the autocompletion box that appears - but you must know it's ID or another locator.

Eran
Reply all
Reply to author
Forward
0 new messages