没有这样的键:从 Poltergeist 迁移到 Selenium 后输入
No such key :Enter after migration from Poltergeist to Selenium
在从 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)>'
#spec/features/comments/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
#spec/support/helpers/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
如果您需要发送回车键,您不应该在 native
上调用任何东西,并且您应该使用小写字母作为符号,这将与 Poltergeist 或 Selenium 作为驱动程序一起工作
find('input[name="comment[body]"]').send_keys(:enter)
见https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method
在从 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)>'
#spec/features/comments/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
#spec/support/helpers/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
如果您需要发送回车键,您不应该在 native
上调用任何东西,并且您应该使用小写字母作为符号,这将与 Poltergeist 或 Selenium 作为驱动程序一起工作
find('input[name="comment[body]"]').send_keys(:enter)
见https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method