【发布时间】:2016-04-12 14:37:51
【问题描述】:
我的下拉列表有问题。列表未填写。我尝试使用 casper.fill 并单击,但它不起作用.. html:
<form id="login-form" novalidate="novalidate" name="login-form" >
<div class="select">
<input name="cardType" value=" " type="hidden"> </input>
<select name="switch-card-type" name="cardType">
<option value="1">text 1
<option value="2">text 2
<option value="3">text 3
</select>
</div>
<div class="select-area custom-select-89578">
<div class="center">text 2</div>
<a tabindex="-1" href="#" class="select-button"></a>
<div class="drop-box drop-undefined drop-89578">
<div class="cssbody">
<ul>
<li class data-index="0">
<a href="#">"text 1"</a>
</li>
<li class ="selected" data-index="1">
<a href="#">"text 2"</a>
</li>
<li data-index="2">
<a href="#">"text 3"</a>
</li>
</ul>
</div>
</div>
</form>
CasperJS:
casper.waitForSelector("form#login-form",function () {
this.fill('form#login-form', {
'switch-card-type':'2'});
});
或
casper.waitForSelector("form#login-bonus-card-form",function () {
this.click(x('//*[@id="login-form"]/div[2]/a'));
this.click(x('//div[@class="drop-box drop-undefined drop-89578"]/div/ul/li[2]/a'));
});
错误,列表未打开
调试很清楚。 第一种情况:
[info] [remote] attempting to fetch form element from selector: 'form#login-card'
[debug] [remote] Set "switch-card-type" field value to 2
[info] [phantom] Step success 7/12: done in 1688ms.
但没有选择真正的价值。没有错误..
第二种情况:
[debug] [phantom] Mouse event 'mousedown' on selector: xpath selector: //*[@id="login-form"]/div[2]/a
[debug] [phantom] Mouse event 'mouseup' on selector: xpath selector: //*[@id="login-form"]/div[2]/a
[debug] [phantom] Mouse event 'click' on selector: xpath selector: //*[@id="login-form"]/div[2]/a
[debug] [phantom] Mouse event 'mousedown' on selector: xpath selector://div[@class="drop-box drop-undefined drop-89578"]/div/ul/li[2]/a
FAIL Cannot dispatch mousedown event on nonexistent selector: xpath selector: //div[@class="drop-box drop-undefined drop-89578"]/div/ul/li[2]/a enter code here
# type: uncaughtError
# file: testcase/test2.js:1378
# error: Cannot dispatch mousedown event on nonexistent selector: xpath selector: //div[@class="drop-box drop-undefined drop-89578"]/div/ul/li[2]/a
# mouseEvent@phantomjs://platform/casper.js:1378:105
# click@phantomjs://platform/casper.js:467:34
# success@phantomjs://code/mvideo_lib.js:353:15
# runStep@phantomjs://platform/casper.js:1577:31
# checkStep@phantomjs://platform/casper.js:404:28
# stack: not provided
因为第一次点击不起作用..
【问题讨论】:
-
您使用哪个 PhantomJS 版本?请注册
resource.error、page.error、remote.message和casper.page.onResourceTimeout活动 (Example)。可能有错误。 -
@ArtjomB。幻影JS 2.1.1。错误添加到描述中。