【问题标题】:Selenium::WebDriver::Error::UnknownError: unknown error: attribute_value.lastIndexOf is not a functionSelenium::WebDriver::Error::UnknownError:未知错误:attribute_value.lastIndexOf 不是函数
【发布时间】: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


【解决方案1】:

您使用的 chromedriverselenium-webdriver 版本严重过时,并且与您使用的 Chrome 版本不兼容 - 请更新它们。

【讨论】:

  • 我已经更新了 chromedriver 和 selenium-webdriver 仍然得到一个错误 'Selenium::WebDriver::Error::UnknownError: unknown error: attribute_value.lastIndexOf is not a function (Session info: chrome= 71.0.3578.80) (驱动信息: chromedriver=2.45.615355 (d5698f682d8b2742017df6c81e0bd8e6a3063189),platform=Mac OS X 10.14.0 x86_64)'
  • @SergeiLagun 现在您已经添加了代码,很明显问题是attribute_value = element[tags_attr[1]]; 返回的内容对于至少一个匹配元素来说不是字符串(因此不会支持拨打lastIndexOf就可以了)。这是因为element[tags_attr[1]] 正在返回不保证是字符串的元素的匹配属性。一种可能的解决方法是更改​​为attribute_value = element.getAttribute(tags_attr[1]);,如果符合要求,它将检查属性(字符串)而不是属性
猜你喜欢
  • 2019-03-31
  • 2021-05-03
  • 2020-11-21
  • 1970-01-01
  • 2019-10-17
  • 1970-01-01
  • 2017-10-31
  • 2017-12-13
  • 1970-01-01
相关资源
最近更新 更多