使用Selenium IDE访问JavaScript变量 [英] Access JavaScript variables with Selenium IDE
问题描述
我想知道是否可以使用Selenium访问页面JavaScript变量。我有一个应用程序正在使用附加到窗口对象的变量。它有一个全局范围,我可以使用 window._myvar
, window ['_ myvar']
, _myvar
,此['_ myvar']
, this._myvar
取决于具体情况。
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.
所以我试图让Selenium回应它。据我所知,在Selenium IDE中,所有运行的上下文是 selenium
。我试过 this.browserbot.getCurrentWindow()._ myvar
, this.browserbot.getCurrentWindow()[_ myvar]
to徒劳无功。我遇到以下错误意外异常:消息 - > eval(匹配[1])未定义
。
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
.
任何人都设法访问其网页的JavaScript?
Anyone managed to access their page's JavaScript?
推荐答案
您应该能够使用getUserWindow而不是getCurrentWindow获取变量。请参阅以下示例:
You should be able to get variables using the getUserWindow rather than getCurrentWindow. See the following example:
assertEval | this.browserbot.getUserWindow().myVar | Hello World!
这篇关于使用Selenium IDE访问JavaScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!