9

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?

1 Answer 1

17

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

assertEval | this.browserbot.getUserWindow().myVar | Hello World!
Sign up to request clarification or add additional context in comments.

2 Comments

Doh! totally forgot about getUserWindow(). Deleting my answer
Does the target parameter need to be wrapped in javascript {...}?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.