[英]WWW::Mechanize::Firefox click button in <div>
I got a big problem. 我遇到了一个大问题。 I have 12 elements with the same class - "comment".
我有12个相同类的元素 - “评论”。 In every is button to click.
在每个按钮中单击。
I need to know how to select (eg. 3 of 12) and click button only there. 我需要知道如何选择(例如,12个中的3个)并仅在那里单击按钮。
Is exist any selector or something? 存在任何选择器或什么? Please give me some advice about that.
请给我一些建议。
$mech->click can take a CSS selector or an XPath query as an argument. $ mech-> click可以将CSS选择器或XPath查询作为参数。 If you know that the button you want to click will always be the third one, you could use something like the nth-of-type CSS selector to pinpoint it.
如果您知道要单击的按钮将始终是第三个按钮,则可以使用类似于第n个类型的 CSS选择器来查明它。
EDIT: An example using XPath based on the OP's comments (I haven't tested this). 编辑:基于OP的评论使用XPath的一个例子(我没有测试过这个)。 Use
qq
to allow variable interpolation inside the XPath statement. 使用
qq
允许在XPath语句中进行变量插值。 Note that you have to backslash escape occurrences of @
so qq
doesn't interpret them as arrays: 请注意,您必须使用
@
反斜杠转义出现,因此qq
不会将它们解释为数组:
my $author = 'xxx';
$mech->click({ xpath => qq(//div[\@class="com" and \@author="$author"]/button) });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.