Filip Dupanović
Filip Dupanović

Reputation: 33640

Access JavaScript variables with Selenium IDE

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?

Upvotes: 9

Views: 14314

Answers (1)

Dave Hunt
Dave Hunt

Reputation: 8223

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

assertEval | this.browserbot.getUserWindow().myVar | Hello World!

Upvotes: 17

Related Questions