Casper.js/Phantom.js不提交数据 [英] Casper.js/Phantom.js not submitting data

查看:111
本文介绍了Casper.js/Phantom.js不提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Casper.js自动提交表单.表单的onSubmit方法返回false,并在发送数据之前运行一些javascript(onclick回调),因此我必须使用clickLabel而不是fill.数据已预先填充,我只需要单击Submit按钮.当我使用Casper执行clickLabel('Submit')时,未提交数据.我在做什么错了?

I'm using Casper.js to automate submitting a form. The form's onSubmit method returns false and runs some javascript (onclick callback) before sending the data, so I have to use clickLabel, instead of fill. The data is prepopulated, I just have to click the Submit button. When I use Casper to do clickLabel('Submit'), the data isn't submitted. What am I doing wrong?

编辑-这是标签的标记:

Edit - here's the markup of the label:

<a class="green_btn white font_18 arrow_btn_pad rad_5" onclick="$.shactivity.eoiPremiumSubmit('expressval');return false;" href="javascript:void(0);">
<span class="fl cursor_p">Submit</span>
<span class="white_right_arrow mar_l_7 block fl mar_t_6 cursor_p"></span>
</a>

推荐答案

在您的情况下,

clickLabel使用//*[text()='Submit']的XPath选择器调用click. click依次尝试使用文本在span上调度mousefownclick事件.但是span上没有任何这样的事件处理程序,因为这是父链接的目的.上面的XPath选择器不会选择作为span元素父级的实际Link.

clickLabel invokes click in your case with the XPath selector of //*[text()='Submit']. click in turn will try dispatch mousefown and click events on the span with the Submit text. But the span won't have any such event handlers on it since this is what the parent link is for. The above XPath selector won't select the actual Link which is a parent of the span element.

您需要点击实际链接以触发操作:

You need to click the actual link to trigger the action:

casper.click(".green_btn.white.font_18.arrow_btn_pad.rad_5");

,并带有XPath表达式以根据文本选择父项:

or with an XPath expression to select the parent based on the text:

var x = require('casper').selectXPath;
casper.click(x("//*[text()='Submit']/.."));

这篇关于Casper.js/Phantom.js不提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆