填写CasperJS中的下拉列表

时间:2016-04-12 14:37:51

标签: jquery phantomjs casperjs

我的下拉列表存在问题。列表未填写。我尝试使用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 

因为第一次点击不起作用..

1 个答案:

答案 0 :(得分:0)

我找到了决心:

if 'abc' in str(my_list):

这是工作。