Skip to content

Commit d568dc9

Browse files
authored
Merge pull request #143 from rubycdp/issue_90/set-value-for-non-focusable-input
Implement focusable?
2 parents f11d477 + 8d29e9a commit d568dc9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/ferrum/node.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def focus
3030
tap { page.command("DOM.focus", slowmoable: true, nodeId: node_id) }
3131
end
3232

33+
def focusable?
34+
focus
35+
true
36+
rescue BrowserError => e
37+
e.message == "Element is not focusable" ? false : raise
38+
end
39+
3340
def blur
3441
tap { evaluate("this.blur()") }
3542
end

spec/node_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,19 @@ module Ferrum
155155
expect(el1 == el2).to be false
156156
end
157157
end
158+
159+
describe "#focusable?" do
160+
before do
161+
browser.go_to("/ferrum/form")
162+
end
163+
164+
context "with hidden input" do
165+
it { expect(browser.at_css("#hidden_input").focusable?).to eq(false) }
166+
end
167+
168+
context "with regular input" do
169+
it { expect(browser.at_css("#form_name").focusable?).to eq(true) }
170+
end
171+
end
158172
end
159173
end

spec/support/views/form.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,7 @@ New line after and before textarea tag
668668
<p>
669669
<input id="special" {custom}="abcdef" value="custom attribute"/>
670670
</p>
671+
672+
<p>
673+
<input id="hidden_input" style="display: none"/>
674+
</p>

0 commit comments

Comments
 (0)