Skip to content

Commit

Permalink
Merge pull request #295 from YusukeIwaki/porting/9352
Browse files Browse the repository at this point in the history
feat: add element validation
  • Loading branch information
YusukeIwaki committed Jan 10, 2023
2 parents 8218aa4 + ac97581 commit 4424dcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/puppeteer/element_handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)

define_async_method :async_wait_for_xpath

def to_element(tag_name)
unless evaluate('(node, tagName) => node.nodeName === tagName.toUpperCase()', tag_name)
raise ArgumentError.new("Element is not a(n) `#{tag_name}` element")
end
self
end

def as_element
self
end
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/element_handle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,13 @@
end
end
end

describe 'to_element' do
it 'should work' do
page.content = '<div class="foo">Foo1</div>'
element = page.query_selector('.foo')
div = element.to_element('div')
expect(div).to be_a(Puppeteer::ElementHandle)
end
end
end

0 comments on commit 4424dcc

Please sign in to comment.