0

I'm testing a smartgwt application by using selenium webdriver. This works pretty well for smartgwt widgets with something like this:

JavascriptExecutor executor = (JavascriptExecutor) context;

return (WebElement) executor.executeScript("return AutoTest.getElement(arguments[0]);", location);

In the above case, location is then something like //IButton[id=isc_button]/

However, we also have a few "basic" html elements on our pages that are no smartgwt widgets, but they do have an id. Hence my attempt to do those as follows (as the above doesn't work for these elements):

JavascriptExecutor executor = (JavascriptExecutor) context;
executor.executeScript("return document.getElementById(arguments[0]);", location);

This doesn't work though. Even with firebug, I tried document.getElementById('xxx') for an element that I know exists with the given ID (as I can find it with the inspector on firebug's html tab) but that didn't work either.

Does anybody know why, and how is it then possible to reach a simple html element through javascript within the generated DOM tree?

Thanks!

Steven De Groote
  • 2,187
  • 5
  • 32
  • 52
  • 2
    "Didn't work" as in "returned nothing"? Are there any `iframe` elements on the page? Can `WebDriver` find those elements when using `context.findElement(By.id('thatId'));`? Do you have any control on how the elements are created? Usually, when an element is created by a direct write into [`element.innerHTML`](https://developer.mozilla.org/en/DOM/element.innerHTML), it can't be then found. – Petr Janeček Jun 25 '12 at 19:49
  • ´this.eventFiringWebDriver.findElement(By.id(location))´ gives me `NoSuchElementException`. The page does contain an iframe btw, but my elment is not in the iframe itself. – Steven De Groote Jun 26 '12 at 08:38
  • Have you tried [Implicit Wait](http://seleniumhq.org/docs/04_webdriver_advanced.html#implicit-waits)? If not, it might save the day. If yes, then I've no idea apart from the `innerHTML` theory - if you create an element via that property, it can't be then found by any means. – Petr Janeček Jun 26 '12 at 11:57
  • Well we always try two more times after a few seconds if the field isn't found, so it must be the `innerHTML` that you mentioned. It also bothered me that even in firebug the `getElementById()` didn't work... – Steven De Groote Jun 26 '12 at 15:17

0 Answers0