YusukeIwaki / puppeteer-ruby

A Ruby port of Puppeteer
Apache License 2.0
284 stars 41 forks source link

How to get the value of an attribute from elements? #302

Closed n1xn closed 1 year ago

n1xn commented 1 year ago

Simple description about the feature

I want to iterate on a list of elements and filter them by attribute-value myAttribute. The code below is ment as reference to understand what I am trying to do.

xpath_info_modal_nodes = '//*[@id="restaurant-about-panel-info"]/div/div'
data_nodes.Sx do |info_modal_node|
   data_attribute = info_modal_node.attribute('myAttribute')
end

Usecase / Motivation

n1xn commented 1 year ago

Figured it out, though it took me a while to get through the API docs.

data_attribute = @page.evaluate('e => e.getAttribute("myAttribute")', info_modal_node)