简体   繁体   English

当有三个时,如何使用 WWW::Mechanize::Firefox 设置值<input>同名标签?

[英]How do I set a value with WWW::Mechanize::Firefox when there are three <input> tags with the same name?

I am using WWW::Mechanize::Firefox to automate some interaction with a web page.我正在使用WWW::Mechanize::Firefox来自动化与网页的一些交互。 Evertyhing works well until I reach a page where I want the script to enter a specific value into an <input...> box. Evertyhing 运行良好,直到我到达我希望脚本在<input...>框中<input...>特定值的页面。 Unfortunatly, this page has three <input... boxes with exaclty the same name:不幸的是,这个页面有三个<input...同名的框:

<input name="search_term" value="" class="inputbox" type="text">

The line in the perl script used to fill the value is perl 脚本中用于填充值的行是

$mech -> field('search_term', $value_search);

Since the name search_term does not identify exactly one <input> tag, the script halts with this error message:由于名称search_term不能准确识别一个<input>标记,脚本会停止并显示以下错误消息:

3 elements found for input with name 'search_term' ....

So, is there a way to indicate which of the three <input> I want to fill?那么,有没有办法指示我要填充三个<input>哪一个?

Edit编辑

ThisSuitIsBlackNot points out that according to the documentation I should be able to set a third parameter to indicate which of multiple matching elements I refer to. ThisSuitIsBlackNot指出,根据文档,我应该能够设置第三个参数来指示我指的是多个匹配元素中的哪一个。 Obviously, this third parameter is ignored so that显然,这第三个参数被忽略,因此

$mech -> field('search_term', $value_search, 1);

still halts with the same error message as without explicitely setting the third parameter.仍然会停止并显示与未明确设置第三个参数相同的错误消息。

I managed to get it working with eval_in_page :我设法让它与eval_in_page一起工作:

$mech -> eval_in_page(
  'document.getElementsByName("search_term")[0].value = "' . $value_search . '"'
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM