没有这样的密钥:从Poltergeist迁移到Selenium后输入

问题描述 投票:0回答:1

在从Poltergeist迁移到Selenium WebDriver / ChromeDriver之后,尝试从旧的Rails 4项目中获取规范。 .native.send_key(:Enter)周围的典型故障

我们应该切换到等效或最佳实践吗?

  17) Comment creation for image changes counter
  Failure/Error: find('input[name="comment[body]"]').native.send_key(:Enter)

  Selenium::WebDriver::Error::UnsupportedOperationError:
    no such key :Enter
  # ./spec/support/helpers/comments_page_helpers.rb:13:in `add_comment'
  # ./spec/features/comments/creation_spec.rb:72:in `block (4 levels) in <top (required)>'
  # ./spec/features/comments/creation_spec.rb:71:in `block (3 levels) in <top (required)>'

#规格/功能/评论/ creation_spec.rb

require 'spec_helper'

feature 'Comment creation', type: :feature, js: true do
  ...
  context 'for image' do
    background do
      open_image_comments_modal section_position: 1, photo_position: 1

      within '.modal-comments-container' do
        add_comment 'First comment message'
      end
    end
  ...
end

#规格/支持/助理/ comments_page_helpers.rb

module CommentsPageHelpers
  ...
  def add_comment(text)
    fill_in 'comment[body]', with: text
    find('input[name="comment[body]"]').native.send_key(:Enter)

    expect(page).to have_css '.comments .comment-body', text: text
  end
  ...
end
ruby-on-rails-4 selenium-webdriver rspec capybara selenium-chromedriver
1个回答
2
投票

如果您需要发送回车键,则不应在native上调用任何内容,并且您应该使用小写字母作为符号,然后使用Poltergeist或Selenium作为驱动程序

find('input[name="comment[body]"]').send_keys(:enter)

https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method

© www.soinside.com 2019 - 2024. All rights reserved.