gpt4 book ai didi

ruby - 如何根据标题查找并单击对象?

转载 作者:行者123 更新时间:2023-12-04 16:20:50 26 4
gpt4 key购买 nike

我想根据标题点击一个 html 对象

<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>

但我的代码不起作用
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

它返回 (eval):14:in 'block (2 levels) in links_with': undefined method 'title' for #<Mechanize::Page::Link:0x1f6aeb0> (NoMethodError)
有什么方法可以使用标题查找和单击对象吗?

最佳答案

几个选项:

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

或者
page.link_with(:node => page.at('a[@title="log in with Google"]'))

关于ruby - 如何根据标题查找并单击对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12335832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com