WebDriver and GWT Suggest Boxes

618 views Asked by At

Ok...I give up :) 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 even tried executing javascript directly to get those values to populate, like this (to no avail):

((JavascriptExecutor) driver).executeScript("document.getElementById('spSelect').value='verizon'");

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

2

There are 2 answers

0
user921104 On BEST ANSWER

Ok, we've figured out our 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

2
Anders On

Try this javascript (from here):

To set the value:

document.getElementById("spSelect")["value"] = "verizon"

To retrieve it:

var value = document.getElementById("spSelect")["value"];