【发布时间】:2018-12-06 23:50:12
【问题描述】:
我正在使用 selenium-webdriver 运行我的黄瓜测试。 当我运行我的功能时,测试失败了
Selenium::WebDriver::Error::UnknownError: 未知错误:attribute_value.lastIndexOf 不是函数
[5] pry(#<Object>)> fill_in 'q', with: company_id
=> #<Capybara::Node::Element tag="input"
path="/html/body/div/div[3]/div/div/div[1]/form/div/input[1]">
[6] pry(#<Object>)> click_on 'Search'
Selenium::WebDriver::Error::UnknownError: unknown error:
attribute_value.lastIndexOf is not a function
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.36.540469
(1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.14.0 x86_64)
from /Users/Sergei/.rvm/gems/ruby-2.3.1@web-autotest/gems/selenium-webdriver-
3.0.8/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
def self.assert_html
# Search whole document instead of current_scope
time = Benchmark.realtime do
document = Capybara.page.document
expect(document).not_to have_css('.pages500')
log_entries = Capybara.page.driver.browser.manage.logs.get(:browser)
log_entries.reject! { |e| %w(INFO WARNING).include? e.level }
$world.puts "Browser log entries: #{log_entries.map(&:to_s)}" unless log_entries.empty?
if Capybara.current_url.start_with? 'https'
js = "tags_attrs = ["\
" ['script, source, audio, iframe', 'src'],"\
" ['object', 'data'],"\
" ['link', 'href'],"\
" ['form', 'action'],"\
" ['video', 'data-stream']"\
"];"\
"incorrect_urls = [];"\
"for (i=0; i<tags_attrs.length; i++) {"\
" tags_attr = tags_attrs[i];"\
" elements = document.getElementsByTagName(tags_attr[0]);"\
" for (j=0; j<elements.length; j++) {"\
" element = elements[j];"\
" attribute_value = element[tags_attr[1]];"\
" if (attribute_value) {"\
" if (attribute_value.lastIndexOf('http://', 0) === 0) {"\
" incorrect_urls.push(attribute_value)"\
" }"\
" }"\
" }"\
"}"\
"return incorrect_urls;"
incorrect_urls = page.execute_script(js)
expect(incorrect_urls).to be_empty
end
end
end
Chrome 版本:版本 70.0.3538.110(官方构建)(64 位) 也许有人知道如何解决它?
【问题讨论】:
-
分享你的完整代码不仅错误。
-
` str = find('.page-breadcrumb').text g = str.match(/(#)(\d+)/) company_id = g.captures.last 在'.tour- view-tabs' do click_on tab end fill_in "Username", with: email fill_in "Password", with: password find('.submitButton-customizable').click visit site sleep 1 fill_in 'q', with: company_id click_on 'Search ' click_on '添加位置' find('#id_input_address').set(address) sleep 1 click_on "保存" sleep 1 click_on "保存" `
-
在问题中更新它。这样我们就可以找出attribute_value.lastIndexOf在哪里
-
我的代码中没有任何“attribute_value.lastIndexOf”。在我单击“搜索”后发生此错误
-
我在 action.rb 文件中找到了这段代码。这是一个 "def self.assert_html" 。此方法用于点击和访问方法
标签: ruby selenium-webdriver cucumber capybara