0

I want to click a html object based on title

<a class="class_id" style="background: url(&quot;http://cdn.server.net/Img/openid/openid-logos.png?v=8&quot;) repeat scroll -1px -518px rgb(255, 255, 255);" href="javascript:openid.signin('google');" title="log in with Google"></a>

but my code doesn't work

require 'rubygems'
require 'mechanize'

agent = Mechanize.new
page = agent.get('http://server.com/')
page = page.link_with(:text=>'log in').click
page = page.link_with(:title=>'log in with Google').click

it returns (eval):14:in 'block (2 levels) in links_with': undefined method 'title' for #<Mechanize::Page::Link:0x1f6aeb0> (NoMethodError)

is there any way how to find and click an object using title?

4

1 回答 1

1

几个选项:

page.links.find{|l| 'log in with Google' == l.attributes[:title]}

或者

page.link_with(:node => page.at('a[@title="log in with Google"]'))
于 2012-09-10T01:30:55.177 回答