简体   繁体   English

如何在Firefox :: Mechanize中触发onchange事件?

[英]How to trigger an onchange event in Firefox::Mechanize?

I'm using Firefox::Mechanize to scrape a website. 我正在使用Firefox :: Mechanize抓取网站。 I'm stuck on a dropdown menu which has an onchange event associated with it. 我停留在一个下拉菜单中,该菜单具有关联的onchange事件。

I'm able to select the option I wanted from the pulldown menu, and I'm able to verify this because the pulldown now shows the option I selected. 我可以从下拉菜单中选择所需的选项,并且可以进行验证,因为下拉菜单现在显示了我选择的选项。 But it doesn't trigger the onchange event associated with it. 但是它不会触发与之关联的onchange事件。

I'm thinking I might need a "click" event after selecting my option, but I'm not sure exactly how to incorporate that. 我想选择选项后可能需要一个“单击”事件,但是我不确定如何将其合并。

Here is the bit of HTML: 这是HTML的一部分:

<select class="" id="select20279" name="20279" onchange="selectAction(this, this.options[this.selectedIndex].value, '20279');">
    <option value="">please choose</option>
    <option value="edit">Edit</option>
    <option value="view">View</option>
    <option value="delete_now">Delete</option>
</select>

Here is my script: 这是我的脚本:

use WWW::Mechanize::Firefox;

my $mech = WWW::Mechanize::Firefox->new( tab => 'current', autoclose => 0 );

$mech->get('http://www.mywebsite.com/');
$mech->select("20279", "view");

Thanks in advance. 提前致谢。

Get the DOM element and then send the change or click event to it: 获取DOM元素,然后向其发送更改或click事件:

my $select = $mech->selector('#select20279', only => 1);
$select->__change();
# or
$select->__click();

See also 也可以看看

http://search.cpan.org/~corion/MozRepl-RemoteObject-0.39/lib/MozRepl/RemoteObject.pm http://search.cpan.org/~corion/MozRepl-RemoteObject-0.39/lib/MozRepl/RemoteObject.pm

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

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