[英]Do I always have to wait before clicking?
I'm writing some tests for my site using WebdriverIO alongside Mocha/Chai, but when I do this: 我正在使用WebdriverIO和Mocha / Chai为我的网站编写一些测试,但是当我这样做时:
it('select application', function(done) {
client
.click('.disciplinetext > table:nth-child(7) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > button:nth-child(1)')
// more stuff
The element doesn't exist yet (wasn't rendered). 该元素尚不存在(未呈现)。 Shouldn't
.click()
implicitly wait for the page to finish loading before it actually attempts to click the element? 不应该
.click()
在实际尝试单击元素之前隐式等待页面完成加载吗?
It works fine if I slap this line before it: 如果我在它之前拍这条线,它工作正常:
.waitFor('.disciplinetext > table:nth-child(7) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > button:nth-child(1)',1000)
But I don't want to have to throw a waitFor
before every .setValue()
, .click()
, .getText()
, or any other API command . 但我不希望有抛出
waitFor
每前.setValue()
.click()
.getText()
或任何其他API命令 。 Am I missing something? 我错过了什么吗?
Is there either a command to wait for the whole page to load, or a setting to make implicitly wait before accessing an element? 是否有等待整个页面加载的命令,或者在访问元素之前隐式等待的设置?
The driver.manage().timeouts().implicitlyWait(ms)
function does exist in the WebdriverJS Reference API Docs . 在DriverdriverJS Reference API Docs中确实存在
driver.manage().timeouts().implicitlyWait(ms)
函数。 This API is for the official Javascript API that Selenium supports and @sircapsalot's excerpt comes from. 此API适用于Selenium支持的官方Javascript API,@ sircapsalot的摘录来自。 However, it is much cleaner than looking at the Google Code and much easier to navigate.
但是,它比查看Google代码要清晰得多,而且更容易导航。
You can set the duration of the implicit wait via: 您可以设置隐式等待的持续时间:
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
The default setting is 0, which is why click() fires instantly. 默认设置为0,这就是click()立即触发的原因。
Obviously this is ac# example, but hopefully you can translate it. 显然这是ac#的例子,但希望你能翻译它。
I think this is aa webdriverjs example: 我认为这是一个webdriverjs的例子:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
It doesn't look like webdriverjs even has an implicit timeout, ergo, no way to change it. 它看起来不像webdriverjs甚至有一个隐含的超时,ergo,没有办法改变它。
1 solution I can think of, is to override the click()
method to something like this... (note that this is psuedo.) 我能想到的解决方案是将
click()
方法覆盖为类似的东西......(注意这是伪造的。)
click = function(what) {
waitFor(what);
super(what);
}
it's an explicit wait, but we can consider it implicit ;)
这是一个明确的等待,但我们可以认为它是隐含的
;)
EDIT: I took a further look into the "inner sanctum" of webdriverjs, and i found this excerpt from here 编辑:我进一步研究了webdriverjs的“内部密室”,我从这里发现了这段摘录
/**
* ...
* @param {number} ms The amount of time to wait, in milliseconds.
* @return {!webdriver.promise.Promise} A promise that will be resolved when the
* implicit wait timeout has been set.
*/
webdriver.WebDriver.Timeouts.prototype.implicitlyWait = function(ms) {
return this.driver_.schedule(
new webdriver.Command(webdriver.CommandName.IMPLICITLY_WAIT).
setParameter('ms', ms < 0 ? 0 : ms),
'WebDriver.manage().timeouts().implicitlyWait(' + ms + ')');
};
Try doing some javascript magic to override this method. 尝试做一些javascript魔术来覆盖这个方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.