使用Watir-WebDriver搜索正则表达式时的StaleElementReferenceError

时间:2013-01-29 19:55:46

标签: selenium watir watir-webdriver

尝试在页面中搜索正则表达式时遇到错误。我使用以下内容来实际定位正则表达式,但我收到了各种错误。

...
browser.script.html.include? "event49"

错误似乎是依赖于浏览器(可能还有环境)。我在Safari,Chrome和Firefox之间来回测试过。 Firefox似乎有间歇性问题。 Chrome,几乎不变。我也在我的PC和Mac之间进行了测试,它似乎是全面的标准。

我对Safari没有任何问题。

此错误来自Firefox:

[remote server] resource://fxdriver/modules/web_element_cache.js:7204:in `fxdriver.cache.getElementAt': Element not found in the cache - perhaps the page has changed since it was looked up (Selenium::WebDriver::Error::StaleElementReferenceError)

此错误来自Chrome:

/Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.29.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': getElementTagName execution failed; (Selenium::WebDriver::Error::StaleElementReferenceError)
Element does not exist in cache

非常感谢任何帮助!

更新:

请参阅以下脚本:

require "rubygems"
require "watir-webdriver"
require "watir-webdriver-performance"
require "rspec"
include Watir
require 'logger'

browser = Watir::Browser.new :chrome

test_site = 'http://laughlin:driveafirestone@fcac-rebrand.laughlin.com/'
browser.goto(test_site)

year_select = browser.select_list(:id => 'universal-year')
browser.select_list(:id => 'universal-year', :disabled => 'disabled').wait_while_present
year_select.select '2010'

make_select = browser.select_list(:id => 'universal-make')
browser.select_list(:id => 'universal-make', :disabled => 'disabled').wait_while_present
make_select.select 'Volkswagen'

model_select = browser.select_list(:id => 'universal-model')
browser.select_list(:id => 'universal-model', :disabled => 'disabled').wait_while_present
model_select.select 'Jetta'

submodel_select = browser.select_list(:id => 'universal-submodel')
browser.select_list(:id => 'universal-submodel', :disabled => 'disabled').wait_while_present
submodel_select.select '2.0T TDI Sedan'

zipcode_input = browser.text_field(:id => 'universal-selectorZip')
zipcode_input.set '53202'

browser.button(:id => 'universal-submit-tires-quote').click

browser.script.html.include? "event49"

browser.close

1 个答案:

答案 0 :(得分:0)

你怎么用

Watir::Wait.until(30) { browser.text.include? "event49" }