扩展Selenium:如何调用命令? [英] Extending Selenium: How to call commands?

查看:161
本文介绍了扩展Selenium:如何调用命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关用户扩展程序 extends selenium 但是我想知道如何从我创建的自定义命令中调用命令。

I read about user extensions and extending selenium but am wondering how to call a command from within a custom command I'm creating.

我在Selenium IDE选项中向Selenium核心扩展(user-extensions.js)添加了类似于以下内容的文件。

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?

推荐答案

您的命令

this.doWaitForPageToLoad(); // doesn't wait at all

不等待,因为您没有在括号中指定等待时间。您应该将它写为

Doesn't wait as you have not specified wait time in brackets. You should write it as

this.doWaitForPageToLoad(30000); // time in milliseconds

游览另一个命令

this.doWaitForElementPresent("example"); // error! undefined function

因为Selenium中没有函数。每当它等待一个元素,它检查该元素是否存在,所以你应该等待时间,直到它可见/存在。
使用For循环和ispresent命令可以做到。

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.

回答

这篇关于扩展Selenium:如何调用命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆