2016-07-05 2 views
0

나는 쉬운 대답으로이 바보 같은 질문이되기를 바라고 있습니다.
casperjs : jquery가 전역 변수를 사용할 수 없습니다.

내가 문제
의 핵심에 도착 제가 테스트 코드를 무식하게 한
풀다운 메뉴를 변경하는 casperjs 스크립트를 쓰고 있어요 (I 하루 기쁨이없는 반 동안 인터넷 검색했습니다) 내 테스트 HTML은 다음과 같다 :

<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    </head> 
    <body style="background-color:powderblue;"> 
    <form> 
    <select id="down"> 
     <option value="volvo">Volvo</option> 
     <option value="saab">Saab</option> 
     <option value="vw">VW</option> 
     <option value="audi">Audi</option> 
    </select> 
    </form> 
    </body> 
    </html> 

실제로 동작하는 Casperjs 스크립트를 사용 JQuery와 :

casper.start("http://192.168.0.14/test.html", function(){ 
    //change the pulldown selection 
    casper.then(function() { 
     this.evaluate(function(){ 
      $('#down').val('vw').change(); 
     }); 
    }); 

    casper.then(function(){ 
      this.capture("screen.png"); 
    }); 
}); 
casper.run(); 

가 지금은 공동의 파라미터를 할을 de이고 선택자값이 인 경우 문자열 대신 변수를 사용하십시오. 그러나이 코드는 작동하지 않습니다 :

var x1='#down'; 
var y1='vw'; 

casper.start("http://192.168.0.14/test.html", function(){ 
    //change the pulldown selection 
    casper.then(function() { 
     this.evaluate(function(){ 
      $(x1).val(y1).change(); 
     }); 
    }); 

    casper.then(function(){ 
      this.capture("screen.png"); 
    }); 
}); 
casper.run(); 

이 것은 어렵지는 않지만 "창"의 모든 조합입니다. 또는 대괄호 표기법이 나를 실패했습니다.
jquery가 멋진 게임을 거부합니다.

내가이 내 깊이에서 내 이름을 써 넣는 것 생각하지 않았다, 도와주세요,하지만 분명히

답변

0

이 시도가 : -

this.evaluate(function(x1, y1){ 
     $(x1).val(y1).change(); 
    }, x1, y1); 

아무것도 내부 샌드 박스입니다 평가하고 당신이 필요합니다 당신이 안으로 사용하고자하는 매개 변수를 전달하십시오

+0

그게 전부 야! 당신은 당신이 무슨 말을하고 있는지 알고 있습니다. 대단히 감사합니다. – Norsak

관련 문제