简体   繁体   English

从Selenium IDE访问Javascript全局变量

[英]Accessing Javascript global variables from Selenium IDE

I'm using the latest Selenium IDE 2.2.0, 我正在使用最新的Selenium IDE 2.2.0,

and I'm having trouble trying to access a javascript global variable that I set in my script. 并且尝试访问在脚本中设置的javascript全局变量时遇到麻烦。

This variable acts as a success flag, so I've put 这个变量充当成功标志,所以我把

Command: waitForCondition
Target: test
Value: 2000

But I get 但是我明白了

[error] test is not defined

I've tried looking at Access JavaScript variables with Selenium IDE , replacing 我试着用Selenium IDE查看Access JavaScript变量 ,替换

Target: this.browserbot.getUserWindow().test

but I also get 但我也得到

[error] this.browserbot is undefined

I could try a different method of setting a success flag like throwing out an alert, but I'd like to know how to access my javascript variables. 我可以尝试使用其他方法来设置成功标志,例如抛出警报,但是我想知道如何访问我的javascript变量。

The docs mentioned storedVars, but that was only for variables stored in selenium so I'm at my wits' end. 该文档提到了storedVars,但这仅适用于存储在硒中的变量,因此我处于机智。

I looked around a bit more and found the following documentation for 我四处张望,发现以下文档

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.

And so 所以

window.test

works! 作品!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM