扩展 Selenium:如何调用命令?
我阅读了有关用户扩展和扩展 selenium 但我想知道如何从我正在创建的自定义命令中调用命令。
我在 Selenium IDE 选项中向 Selenium 核心扩展 (user-extensions.js) 添加了一个类似于以下内容的文件。
// selenium-action-example.js
Selenium.prototype.doExample = function() {
this.doOpen("/"); // doesn't waitForPageToLoad like the command does
// These two commands are equivalent to the clickAndWait command. NOT!
// For proof, see the filterForRemoteControl function:
// http://code.google.com/p/selenium/source/browse/trunk/ide/src/extension/content/formats/formatCommandOnlyAdapter.js?r=8284#68
this.doClick("css=a#example");
this.doWaitForPageToLoad(); // doesn't wait at all
this.doClick("link=Example");
this.doWaitForElementPresent("example"); // error! undefined function
this.doClick("example");
};
换句话说,我如何在自定义操作中的点击之间等待事件?
I read about user extensions and extending selenium but am wondering how to call a command from within a custom command I'm creating.
I added a file similar to the following to Selenium core extensions (user-extensions.js) in Selenium IDE Options.
// selenium-action-example.js
Selenium.prototype.doExample = function() {
this.doOpen("/"); // doesn't waitForPageToLoad like the command does
// These two commands are equivalent to the clickAndWait command. NOT!
// For proof, see the filterForRemoteControl function:
// http://code.google.com/p/selenium/source/browse/trunk/ide/src/extension/content/formats/formatCommandOnlyAdapter.js?r=8284#68
this.doClick("css=a#example");
this.doWaitForPageToLoad(); // doesn't wait at all
this.doClick("link=Example");
this.doWaitForElementPresent("example"); // error! undefined function
this.doClick("example");
};
In other words, how can I wait for things between clicks within a custom action?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的命令
不等待,因为您没有在括号中指定等待时间。您应该将其写为
Tour another Command
,因为 Selenium 中没有函数。每当它等待一个元素时,它都会检查该元素是否存在,因此您应该等待时间直到它可见/存在。
使用 For 循环和 ispresent 命令就可以做到这一点。
问候
Your command
Doesn't wait as you have not specified wait time in brackets. You should write it as
Tour another Command
as no function is there in Selenium. whenever it waits for an element it checks that element is present or not so you should wait for time until it is visible/present.
Using For loop and ispresent commands you can do it.
Regards
等待页面加载在当前版本的 Selenium 中不起作用。据我所知,这是因为 doWaitForPageToLoad 将等待推迟到当前 Selenium IDE 命令结束,即等待页面加载会停止 test 执行,直到页面加载完毕,但不会执行此函数的实际 javascript 函数的执行。
此时您必须将函数一分为二。
Waiting for an page load does not to work in current versions of Selenium. As far as I can see, this is because the doWaitForPageToLoad defers the waiting until the end of the current Selenium IDE command, i.e. waiting for a page load stops the test execution until the page has loaded, but not the execution of the actual javascript function that this was executed in.
You will have to split your function in two at this point.