不一致地得到错误(Watir :: Wait :: TimeoutError)
我是黄瓜新手,有时运行脚本我收到错误
(Watir::Wait::TimeoutError)
我没有找到任何特定的模式。 任何帮助将非常感谢。
非常感谢
首先,确保您需要适当的库来进行watir-webdriver / wait。
require "watir-webdriver/wait"
Watir有一些声明对象等待时间的方法,例如(通过Watir Webdriver / Waiting ):
明确的等待
您可以使用四种内置方法使您的等待体验更加愉快(并从您的代码中删除那些邪恶的睡眠语句)
Watir::Wait.until { ... } #=> you can wait for a block to be true object.when_present.set #=> you can do something when it's present object.wait_until_present #=> you just wait until something is present & visible object.wait_while_present #=> you just wait until something disappears
Watir还有一种方法可以设置驱动程序执行之间的隐式等待时间。
隐含的等待
作为替代方法,您可以使用WebDriver的隐式等待来指定脚本在超时之前尝试查找元素的最长时间(以秒为单位)。 这是通过设置底层驱动程序的属性来完成的:
require 'watir-webdriver' b = Watir::Browser.new b.driver.manage.timeouts.implicit_wait = 3 #=> always wait 3 seconds