eval_in_页面javascript执行在firefox中有效,但在phantomjs中无效
我正在尝试使用eval_in_页面javascript执行在firefox中有效,但在phantomjs中无效,javascript,html,perl,phantomjs,mechanize,Javascript,Html,Perl,Phantomjs,Mechanize,我正在尝试使用Mechanize::PhantomJS在Perl中自动化javascript页面。用户在确认警报中单击OK或cancel后,页面上会执行一些javascript。因为我不知道如何按下OK键,所以我直接执行javascript。问题是,以下脚本在使用firefox时运行良好(这里我使用的是Mechanize::firefox),但在使用Mechanize::PhantomJS $mech->eval_in_page(<<'JS'); closeChildWi
Mechanize::PhantomJS
在Perl中自动化javascript页面。用户在确认警报中单击OK或cancel后,页面上会执行一些javascript。因为我不知道如何按下OK键,所以我直接执行javascript。问题是,以下脚本在使用firefox时运行良好(这里我使用的是Mechanize::firefox
),但在使用Mechanize::PhantomJS
$mech->eval_in_page(<<'JS');
closeChildWindows();
commandInProgress = true;
document.dataForm.target="_self";
document.dataForm.method='post';
document.dataForm.action="ReviewApptAction";
document.dataForm.submit();
JS
此按钮调用的功能如下:
function bookAppointment()
{
if ( confirm("Book this appointment?") )
{
if ( !commandInProgress) {
closeChildWindows();
commandInProgress = true;
document.dataForm.target="_self";
document.dataForm.method='post';
document.dataForm.action="ReviewApptAction";
document.dataForm.submit();
}
else {
alert("Request has been submitted but not yet processed by the server. Please press OK and wait for response...");
}
}
return;
}
首先,我使用$mech->confirm('Really do this?'[=>1])
在确认对话框中单击OK,但这不起作用。因此,我只是在单击OK之后发出了命令。您误读了:
$mech->确认('Really do this?'[=>1])
记录确认(默认为“1”或“ok”[…]
正如Artjom B.在评论中所说,[=>1]
表示第二个参数是可选的,默认值是1。如果要传递第二个参数,必须删除括号,因为以下是无效的Perl代码,并将导致语法错误:
$mech->confirm( 'Really do this?' [ => 1 ]);
“‘真的这么做?’”附近的./foo第42行出现语法错误。[”
由于编译错误,./foo的执行已中止。
要点击“ok”,请执行以下操作:
或者,由于1是默认值,只需:
$mech->confirm( 'Really do this?' );
如果要取消该对话框,请使用:
$mech->confirm( 'Really do this?' => 0 );
最后,有人遵循这样的礼仪(发布为CW)。我从未使用过Perl,因此我不喜欢根据假设编写答案。好吧,你解决了问题,告诉OP编写答案是正确的。我现在使用的是
WWW::Mechanize::PhantomJS
,因此我认为只编写一个答案而不是等待OP会更快。
$mech->confirm( 'Really do this?' );
$mech->confirm( 'Really do this?' => 0 );