views:

1550

answers:

2

I'm wondering if it's possible to access page JavaScript variables with Selenium. I have an application that's using a variable attached to the window object. It has a global scope and I can access it either with window._myvar, window['_myvar'], _myvar, this['_myvar'], this._myvar depending on the context.

So I tried to get Selenium to echo it. As far as I understand, in Selenium IDE the context in which everything runs is selenium. I tried doing this.browserbot.getCurrentWindow()._myvar, this.browserbot.getCurrentWindow()[_myvar] to no avail. I get bumped with the following error Unexpected Exception: message -> eval(match[1]) is undefined.

Anyone managed to access their page's JavaScript?

+4  A: 

You should be able to get variables using the getUserWindow rather than getCurrentWindow. See the following example:

assertEval | this.browserbot.getUserWindow().myVar | Hello World!
Dave Hunt
Doh! totally forgot about getUserWindow(). Deleting my answer
AutomatedTester
worked like a charm ;)!
kRON
A: 

I tried that suggestion but Selenium says [error] Actual value 'null' did not match...