diff --git a/CHANGELOG.md b/CHANGELOG.md index 94dd088..72779e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ [rubycdp/ferrum#716] ### Fixed +- Number fields are typed with real key presses like text fields, so `clear:` and `rapid:` apply, their value was set + from JS with no key events - `value` of a multiple select includes the selected options in an ``, it returned only the others - `Node#send_keys` focuses an element without focus instead of clicking it, so a checkbox isn't toggled and a link isn't followed, and the keys go to the end of a filled field instead of where the click put the caret diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index f881026..3f71244 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -253,7 +253,7 @@ this.trigger(node, "focus"); this.setValue(node, ""); - if (node.type == "number" || node.type == "date" || node.type == "range" || node.type == "time" || node.type == "month" || node.type == "week") { + if (node.type == "date" || node.type == "range" || node.type == "time" || node.type == "month" || node.type == "week") { this.setValue(node, value); this.input(node); } else if (node.type == "datetime-local") { diff --git a/lib/capybara/cuprite/node/typing.rb b/lib/capybara/cuprite/node/typing.rb index 772cf89..de4819b 100644 --- a/lib/capybara/cuprite/node/typing.rb +++ b/lib/capybara/cuprite/node/typing.rb @@ -4,7 +4,7 @@ module Capybara module Cuprite class Node < Capybara::Driver::Node module Typing - TYPED_INPUTS = %w[text password email search tel url].freeze + TYPED_INPUTS = %w[text password email search tel url number].freeze SET_OPTIONS = %i[rapid clear].freeze CLEAR_ERROR = "clear: takes nil, :none, :backspace or an Array of keys" RAPID_SET_LENGTH = 30 diff --git a/spec/node_spec.rb b/spec/node_spec.rb index 15858f2..c866f1f 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -537,6 +537,13 @@ expect(element.value).to eq("-100") end + it "appends to a number field with clear: :none" do + element = @session.find(:css, "#change_me_number") + element.set(12) + element.set(34, clear: :none) + expect(element.value).to eq("1234") + end + it "fires the keydown event" do expect(@session.find(:css, "#changes_on_keydown").text).to eq("6") end