1

我想知道以下是否可能:

@wait = Selenium::WebDriver::Wait.new timeout: 10
# ...do stuff...

# Stuff gets really slow here. Better increase the timeout.
def janky_method()
    old_timeout = @wait.timeout
    @wait.timeout += 50
    e = @wait.until { @selenium.find_element :css, 'div#page-loads-rock' }
    @wait.timeout = old_timeout
    e
end

到目前为止,我看到的唯一解决方案是启动一个新Wait驱动程序。我可以更改现有的超时时间吗?

4

1 回答 1

1

Selenium::WebDriver::Wait 类不提供任何修改超时(即@timeout变量)的方法。

如果您希望能够修改它,您将不得不修改 Selenium::WebDriver::Wait 类:

require 'selenium-webdriver'
class Selenium::WebDriver::Wait
  attr_accessor :timeout
end

然后,这将允许您与@timeout变量进行交互,就像您在janky_method.

注意:我不确定这种方法是否比仅仅为特定场景创建新的等待有什么好处。

于 2013-07-15T16:13:01.533 回答