GWT SuggestBox and Selenium

245 views
Skip to first unread message

Pedro Perez

unread,
Jan 26, 2012, 12:06:11 PM1/26/12
to Google Web Toolkit
Hello,

I've posted this in the Google Group for Selenium, posting here as
well hoping someone has some Selenium experience that has seen this--

What is the best way to select values out of a GWT Suggest Box using
WebDriver? I'm using FirefoxDriver, and so far nothing seems to pick
values out of a GWT suggestBox...not sendKeys, not selenium.keyUp,
anything.
I've tried executing Javascript directly to get those values to
populate. Is there a better
way? If not, what is the "best" way to get values out of a GWT
suggest
Box?
Many thanks in advance.

Cheers
Pedro

l3dx

unread,
Jan 26, 2012, 12:23:05 PM1/26/12
to google-we...@googlegroups.com
IIRC, you need two selectors/webelements

  1. The textbox - here you sendKeys() and click()
  2. The suggestPopup - where you select a suggestion
I used CSS to select the textbox, and XPath to select the desired suggestion. I don't have the source code available right now, but I  hope this helps a little bit :-)

/l3dx

Evgeny Mayzel

unread,
Jan 30, 2012, 2:08:22 AM1/30/12
to google-we...@googlegroups.com
#Python Script:

def suggestBox(self,text):
    driver = self.driver
    d=driver.find_element_by_id("suggestion_box").send_keys(text)
    time.sleep(3) #wait fo suggestions to appear (could take longer)
    path="//tr/td[text() = "+"\""+text+"\"]" #choosing the inputed text from the suggestion Box
    e=driver.find_element_by_xpath(path)
    e.click()


Good Luck :)

Pedro Perez

unread,
Jan 31, 2012, 7:39:37 PM1/31/12
to Google Web Toolkit
Thanks everyone for your help. We ended up finding the problem:

We were setting explicit IDs on our elements, so our tests can grab
them easier, in GWT this is done via:

usernameLabel.getElement().setId("consoleLoginPageUserNameInput");

This works fine for most GWT inputs, but for the SuggestBox it is
handled a bit differently:

spSelect.getElement().getElementsByTagName("input").getItem(0).setId("spSelect");

After grabbing the correct inner table, we are able to interact with
this input with Selenium just fine. Hope this helps someone.
Cheers
Pedro
Reply all
Reply to author
Forward
0 new messages