javascript - 从 Selenium IDE 访问 Javascript 全局变量

标签 javascript testing selenium selenium-ide

我正在使用最新的 Selenium IDE 2.2.0,

我在尝试访问我在脚本中设置的 javascript 全局变量时遇到了问题。

这个变量作为一个成功标志,所以我把

Command: waitForCondition
Target: test
Value: 2000

但是我明白了

[error] test is not defined

我试过查看 Access JavaScript variables with Selenium IDE , 替换

Target: this.browserbot.getUserWindow().test

但我也明白了

[error] this.browserbot is undefined

我可以尝试另一种设置成功标志的方法,例如发出警报,但我想知道如何访问我的 javascript 变量。

文档中提到了 storedVars,但这仅适用于存储在 selenium 中的变量,所以我束手无策。

最佳答案

我环顾四周,找到了以下文档

Command: waitForEval

Note that, by default, the snippet will run in the context of the "selenium" object
itself, so this will refer to the Selenium object. Use window to refer to the window 
of your application, e.g. window.document.getElementById('foo')

If you need to use a locator to refer to a single element in your application page, 
you can use this.browserbot.findElement("id=foo") where "id=foo" is your locator.

等等

window.test

有效!

关于javascript - 从 Selenium IDE 访问 Javascript 全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17970150/

相关文章:

java - setPreference for FirefoxProfile 但无法关闭“保存”对话框

javascript - jquery分页插件的使用方法

javascript - 通过添加父名称来创建元素的对象链

testing - 边界值分析 - 何时使用二值或三值?

android - Android 2.1中的ActivityInstrumentationTestCase2有问题吗?

testing - 在 Selenium IDE 中,如何获取基本 url 的值

javascript - 有多少业务逻辑属于 Vuex?

javascript - 在javascript中根据变量值定义对象字段名称

unit-testing - 通过嵌入式脚本从应用程序内部进行测试是个好主意吗?

python - 如何定位在python selenium中单击按钮后出现的网页上的元素