WebDriver and GWT Suggest Boxes

648 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 best solutions below

0
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
On

Try this javascript (from here):

To set the value:

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

To retrieve it:

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