2017-01-13 6 views
0

https://frontier.com/login에 로그인하는 CasperJS 스크립트를 작성하려고합니다. 내가 액세스의 범위 (. 예를 들어 ng-model='login.loginId')에서 개최 된 값을 변경할 수 없습니다 보인다 그래서 AngularJS와 사용CasperJS를 사용하여 AngularJS 입력 필드를 양식 태그 밖으로 가져 오는 방법

  1. : 때문에

    나는 문제가 있습니다. 요소에 직접 값을 설정해도 아무런 효과가 없습니다.

  2. 입력 필드

  3. 는 폼 요소가 너무 CasperJS와 일반 fillSelectors()

  4. casper.exists('input#fid-login-inline-username') true를 반환 할 수 없습니다 사용하여 포장하지만, casper.sendKeys('input#fid-login-inline-username', 'blah') 말하는 오류를 제공하지 않는 [error] [remote] mouseEvent(): Couldn't find any element matching 'input#fid-login-inline-username' selector

작업 할 필드는 다음과 같습니다.

  1. input#fid-login-inline-password
  2. - click()

에 대한 그래서, 어떻게 각도 범위에 캐스퍼에서 두 개의 입력 필드를 수정합니까? 여기

내가 무엇을 시도했다의 예입니다

casper.start('https://frontier.com/login', function() { 
    this.echo('waiting for password input field'); 
    this.waitForSelector("input#fid-login-inline-password"); 
}); 

casper.then(function() { 
    if (this.exists('input#fid-login-inline-username')) { 
    this.echo('username input exists'); 
    } 
    if (this.exists('input#fid-login-inline-password')) { 
    this.echo('password input exists'); 
    } 
    this.echo('filling in username and password'); 
    // these fields are not in a form element, so, use sendKeys to enter text... 
    // the above echoes print the fields exist, and then these sendKeys 
    // operations emit an error that the fields don't exist. 
    this.sendKeys('input#fid-login-inline-username', '[email protected]'); 
    this.sendKeys('input#fid-login-inline-password', 'some-password'); 
}); 

casper.then(function() { 
    this.echo('clicking login button'); 
    this.click('div.login-form-container button.btn-primary'); 
}); 

답변

0

내가 그것을 알아 냈어. 앱이 ID 당 두 개의 입력 요소를 생성하고 있습니다. 두 번째 이벤트를 얻으면 값을 설정하고 AngularJS가 이벤트를 트리거하도록 이벤트를 트리거 할 수 있습니다.

function login(un, pw) { 
    $($('[ng-model="login.loginId"]')[1]).val(un).trigger('input'); 
    $($('[ng-model="login.password"]')[1]).val(pw).trigger('input'); 
}; 
this.evaluate(login, username, password);