2016-04-12 32 views
1

Açılır listeyle ilgili bir sorunum var. Liste doldurulmadı. Ben casper.fill kullanmak ve tıklama çalışıyorum, ama çalışmıyor .. html:Açılır listeyi doldurun CasperJS

<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'}); 
}); 

veya

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')); 
     }); 

Hata, liste o değil kalem

Hata ayıklama açık. İlk durumda :

[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. 

Ama gerçekten değer seçilmedi. hatalar yoktur ..

İkinci durumda: İlk tıklama çalışmalarını does't

[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 
# [email protected]://platform/casper.js:1378:105 
# [email protected]://platform/casper.js:467:34 
# [email protected]://code/mvideo_lib.js:353:15 
# [email protected]://platform/casper.js:1577:31 
# [email protected]://platform/casper.js:404:28 
# stack: not provided 

Çünkü ..

+0

Hangi PhantomJS sürümünü kullanıyorsunuz? Lütfen "resource.error", "page.error", "remote.message" ve "casper.page.onResourceTimeout" etkinliklerine kayıt olun ([Örnek] (https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file -2_caspererrors-js)). Belki de hatalar vardır. –

+0

@ArtjomB. PhantomJS 2.1.1. Hatalar tanım alanına ekleyin. –

cevap

0

O kararlılık bulmuştu:

casper.waitForSelector("form#login-bonus-card-form", 
     function success() { 
      this.click('.select-button'); 
      this.click(x('//div[@class="csbody"]/ul/li[2]/a')); 
     }); 

Bu iş.