Casper.js/Phantom.js not submitting data

匆匆过客 提交于 2019-12-25 04:22:23

问题


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>

回答1:


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");

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

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


来源:https://stackoverflow.com/questions/25186595/casper-js-phantom-js-not-submitting-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!