简体   繁体   English

点击之前我总是要等吗?

[英]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.

相关问题 如何在使用 Chrome 扩展程序单击元素之前等待元素加载到第二页? - How do I wait for an element to load on second page before clicking on it with my Chrome Extension? CSS3过渡似乎需要“热身”时间才能开始? 我是否需要增加等待时间? - CSS3 transitions seem to need a “warmup” time before they kick off? Do I have to add a wait? 我何时必须在量角器中等待诺言? - When do I have to wait for a promise in Protractor? 我是否必须等待 void 异步函数? - Do I have to wait for void async functions? 在单击按钮之前等待上传完成 - Wait for upload to complete before clicking a button 单击提交按钮之前,如何检查图像是否已生成? - How do I check if image is generated before clicking submit button? 我如何在返回填充数组之前在NodeJS中等待foreach? - How do I wait for foreach in NodeJS before returning the populated array? 如何在执行代码之前等待slideToggle完成? - How do I wait for the slideToggle to complete before executing code? 在返回 function 的变量之前,如何等待 promise 完成? - How do I wait for a promise to finish before returning the variable of a function? 在继续前进之前,如何等待带有异步调用的.map()完成? - How do I wait for a .map() with asynchronous calls to finish before moving on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM