0

I want to use WebDriver to execute some javascripts on the application i am testing. Im using the following code:

JavascriptExecutor js = (JavascriptExecutor) driver;
String label = (String)js.executeScript("return document.g.nodes[1].label", null); 

g global javascript object in the page. if i inspect it from the console using inspect elements i see that everything is there... though when i execute this script im thrown an exception stating "Cannot create node property from undefined".

Witch g is for some reason undefined in the page.

anyone have any ideas?

its not a problem with timing since im working in debug and manually wating for page to load completly.

thanks

Mike Kwan
  • 23,549
  • 10
  • 59
  • 94
Eli
  • 181
  • 1
  • 3
  • 10

1 Answers1

1

Aren't javascript objects attached to window rather than document?

At least I have always used window.whatever from webdriver and it works nicely.

Derek Ekins
  • 11,115
  • 6
  • 59
  • 68
  • What is the difference between window and document? More precisely difference between document.activeElement and window.activeElement – Ripon Al Wasim Aug 07 '12 at 08:18