【发布时间】:2015-01-06 02:26:59
【问题描述】:
我正在尝试使用Mechanize::PhantomJS 在 Perl 中自动化一个 javascript 繁重的页面。用户在确认警报中单击确定或取消后,页面上会执行一些 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
在 PhantomJS 中,脚本通过这些行不会产生任何错误,但不会在页面上执行任何操作,这意味着我没有得到任何结果,例如最后提交表单。有谁知道这里发生了什么?
我想使用 Mechanize::PhantomJS,因为它允许我同时运行脚本的多个实例,这与 firefox 不同。
让我更清楚一点:我必须按下一个附加了 onclick javascript 的按钮:
<a href="javascript:bookAppointment()" onmouseover="window.status='Next Screen';return true" onmouseout="window.status='';return true">
<img src="../images/include/buttonnext.gif" width="61" height="16" border="0" alt="Next Screen"></a>
这个按钮调用的函数是这样的:
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 点击之后的命令。
【问题讨论】:
标签: javascript html perl phantomjs mechanize