2017-05-15 5 views
-1

내가 직면하고있는 문제에 대한 도움이 필요하고 node-horseman이 처리 할 수 ​​있다고 확신합니다.Horseman.js -> handling window.confirm

"window.confirm"경고를 받아들이고 많은 성공을 거두었습니다. 기본적으로 버튼을 클릭 한 후 기수를 사용하여 확인 메시지를 "수락"할 수 있기를 원합니다.

.at (이벤트, 콜백) 콜백와 페이지 이벤트에 에 응답 :

워드 프로세서를 통해가는,이를 발견했다.

TypeError: horseman.at is not a function 

난 무엇 : 내가 어떤 .open

horseman 
    .at('confirm', function(msg) { 
     return msg === 'Do you accept?' ? true : false; 
    }) 

전에이 같은 .at을 넣을 때

.at('confirm', function(msg) { 
    return msg === 'Like this?' ? true : false; 
}) 

그럼에도 불구하고, 내가 말하는 오류가 찾고 : 노드 기수를 사용하여 window.confirm을 수락하는 방법.

도움이 될 것입니다.

답변

0

독서를 통해 this answer을 읽으면이 문제를 해결할 수있었습니다.

horseman 
    .open(myUrl) 
    .evaluate(function(){ 
     var realConfirm=window.confirm; 
     // override the window.confirm function just once 
     window.confirm=function(msg){ 
      window.confirm = realConfirm; 
      if (msg=="message I am Expecting"){ 
       return true; 
      }else{ 
       return false; 
      } 
     }; 
    }) 
    .click('#mybutton') 

그리고이 일 :

대신 .at 를 사용하는 나는 다음과 같은했다!

기본적으로 window.confirm 함수를 호출 할 때 다음 함수를 덮어 쓰고 실행 중에 이전 값으로 복원합니다.

다른 사람들에게도 도움이되기를 바랍니다.