select

- 1.0.0
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (1)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.2 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- What's this?
select(pattern)
public
Returns a collection reference by finding it through a CSS pattern in the DOM. This collection can then be used for further method calls. Examples:
page.select('p') # => $$('p'); page.select('p.welcome b').first # => $$('p.welcome b').first(); page.select('p.welcome b').first.hide # => $$('p.welcome b').first().hide();
You can also use prototype enumerations with the collection. Observe:
# Generates: $$('#items li').each(function(value) { value.hide(); }); page.select('#items li').each do |value| value.hide end
Though you can call the block param anything you want, they are always rendered in the javascript as ‘value, index.’ Other enumerations, like collect() return the last statement:
# Generates: var hidden = $$('#items li').collect(function(value, index) { return value.hide(); }); page.select('#items li').collect('hidden') do |item| item.hide end

Gotcha with method calls inside select loop
Keep in mind that any methods you call on the object in the select loop will be strung together when the Javascript is rendered. For example:
page.select(".shipping_type_fee").each do |td| td.down("span").update("--").show td.down("img").hide end
will be rendered as:
$$('.shipping_type_fee').each(function(value, index) { value.down("span").update("--").show().down("img").hide(); });
This is probably not what you want!