我们最终在 Selenium 上编写了一个层,通过将调用包装在可选循环中来处理这种情况。所以当你这样做时:
@browser.click "#my_button_id"
Run Code Online (Sandbox Code Playgroud)
它会做类似于上面 AutomatedTester 建议的事情:
class Browser
def click(locator)
wait_for_element(locator, :timeout => PAGE_EVENT_TIMEOUT)
@selenium.click(locator)
end
def wait_for_element(locator, options)
timeout = options[:timeout] || PAGE_LOAD_TIMEOUT
selenium_locator = locator.clone
expression = <<EOF
var element;
try {
element = selenium.browserbot.findElement('#{selenium_locator}');
} catch(e) {
element = null;
};
element != null;
EOF
begin
selenium.wait_for_condition(expression, timeout)
rescue ::Selenium::SeleniumException
raise "Couldn't find element with locator '#{locator}' on the page: #{$!}.\nThe locator passed to selenium was '#{selenium_locator}'"
end
end
end
Run Code Online (Sandbox Code Playgroud)
包装器还做了其他事情,比如允许通过按钮/输入标签等进行搜索(因此包装器的存在不仅仅是为了计时问题,这只是我们放在那里的事情之一。)
| 归档时间: |
|
| 查看次数: |
4052 次 |
| 最近记录: |