Google Web Toolkit and id

There are at least two points of pain when trying to automate a GWT with Selenium (and Selenium IDE). The easier of the two is that GWT does not assign id’s to its widgets by default which then necessitates the use of structural locators like XPath and CSS which can lead to brittle scripts. And the solution is of course easy, but requires developer assistance.

Method One – setting the id

According to Developer’s Guide – CSS Style the cleanest way to do this is by manipulating the DOM

Button b = new Button();
DOM.setElementAttribute(b.getElement(), "id", "my-button-id")

This is easy to do from a technical perspective, but it also means ‘extra’ work for the developers and getting buy-in from management that ‘Yes, if we are to really be successful in the this whole automation thing, we do need to change the app’ which can be hard.

Method Two – ensureDebugId

This seems like a bit of a kludge, but apparently there is a bit of a performance hit to the first method so they have come up with another way of conditionally including id on elements if you have the module enabled on your app.

Button b = new Button();

A few notes around this

  • It will override an existing id with this one
  • The id it produces will be prefixed with gwt-debug-

It still requires that the application change for automation purposes, but it can be turned off in production so is perhaps more palatable to folks. Of course, it also means you cannot run your Se scripts against production which seems like an artificial limitation to me.

Method Three – setId

It appears that elements have a method to directly set the id without going to the DOM directly.

Button b = new Button();

The other problem is the oh-so-fun ‘it looks like a button but is not actually a button’ problem which is not as simple to solve. But as far as the locator problem goes, no more whining! :)

Comments 1

  1. bv bhi wrote:

    Hi Adam,
    How to set ids for grid-rows?

    Posted 27 Jun 2013 at 10:17 am

Trackbacks & Pingbacks 1

  1. From Confluence: Testing on 02 Mar 2017 at 7:31 am

    List of widgets that have GWT Debug mode for generating object ID

    Additional info:  From

Post a Comment

Your email is never published nor shared. Required fields are marked *