2017-12-12 5 views
1

私はPhantonJSを使ってプロトンメールに入ってみようとしています。私はログインとパスワードを入力し、ログインボタンを押したいと思います。押さないでください。私が押すことを試みたとき。そう。PhantomJSを使ってプロトンメールにログインする

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    var lbx1x1x1a = document.getElementById("login_btn"); 
    var lbx1x1x1e = document.createEvent("MouseEvents"); 
    lbx1x1x1e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
    lbx1x1x1a.dispatchEvent(lbx1x1x1e); 
},ps,p); 

動作しません、何も起こりません

だから:動作しません

var point = page.evaluate(function() { 
    var element = document.getElementById('login_btn'); 
    var rect = element.getBoundingClientRect(); 
     return { 
       x: rect.left + Math.floor(rect.width/2), 
       y: rect.top + Math.floor(rect.height/2) 
     }; 
}); 
point.x=Math.floor(point.x); 
point.y=Math.floor(point.y); 
console.log(point.x+" "+point.y); 
page.sendEvent('click', point.x, point.y); 

は、何も

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    document.getElementById("pm_login").submit(); 

},ps,p); 

が動作しない起こりませんが、ログのフィールドとパスワードは削除されました

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").focus(); 
},ps,p); 

page.sendEvent('keypress', "123\r"); 
page.sendEvent('keypress', page.event.key.A, null, null, 0x02000000 | 0x08000000); 

が動作しない、何も

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    document.getElementById("login_btn").focus(); 
},ps,p); 

page.sendEvent('keypress', "\r"); 
page.sendEvent('keypress', page.event.key.A, null, null, 0x02000000 | 0x08000000); 

が動作しない起こりません、何も起こりません。 これ以上アイデアはありませんか? ありがとうございます。

ファントムズ2.1.1

こんにちは! Vaviloffに感謝します)。 エラーを検出するために、そのコードを貼り付けます。

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    document.getElementById("login_btn").click(); 
    var lbx1x1x1a = document.getElementById("login_btn"); 
    var lbx1x1x1e = document.createEvent("MouseEvents"); 
    lbx1x1x1e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
    lbx1x1x1a.dispatchEvent(lbx1x1x1e); 
},ps,p); 

    page.onResourceError = function(resourceError) { 
     console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')'); 
     console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString); 
    }; 

    page.onConsoleMessage = function(msg, lineNum, sourceId) { 
     console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")'); 
    }; 

    page.onError = function(msg, trace) { 
     var msgStack = ['ERROR: ' + msg]; 
     if (trace && trace.length) { 
      msgStack.push('TRACE:'); 
      trace.forEach(function(t) { 
       msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : '')); 
      }); 
     } 
     console.error(msgStack.join('\n')); 
    }; 

エラーはありません。 phantomjsを実行すると、コンソールで次のメッセージが表示されますが、その前にログインをクリックしようとしています。

TypeError: undefined is not a constructor (evaluating 'navLang.includes("-")') 
https://protonmail.com/js/site.js?rel=b38297243e:6 
https://protonmail.com/js/site.js?rel=b38297243e:2 in j 
https://protonmail.com/js/site.js?rel=b38297243e:2 in fireWith 
https://protonmail.com/js/site.js?rel=b38297243e:2 in ready 
https://protonmail.com/js/site.js?rel=b38297243e:1 in J 

同じページで同時に私は他の要素をクリックすることができ、それは動作します。次のコードは、必要に応じて動作します。

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    var lbx1x1x1a =document.getElementsByClassName ("loginForm-btn-help")[0]; 
    var lbx1x1x1e = document.createEvent("MouseEvents"); 
    lbx1x1x1e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
    lbx1x1x1a.dispatchEvent(lbx1x1x1e); 

},ps,p); 

または

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    var lbx1x1x1a =document.getElementsByClassName ("loginForm-actions-main pm_button primary pull-right loginForm-btn-submit")[0]; 
    var lbx1x1x1e = document.createEvent("MouseEvents"); 
    lbx1x1x1e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
    lbx1x1x1a.dispatchEvent(lbx1x1x1e); 
},ps,p); 

ScreenShot - signup

他の要素は、まったくログインクリッカブルません。 私はそれを押すことができません。 キャッチはどこですか?おかげさまで

document.getElementById("login_btn").click(); 

、そのコード:

var lbx1x1x1a = document.getElementById("login_btn"); 
var lbx1x1x1e = document.createEvent("MouseEvents"); 
lbx1x1x1e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
lbx1x1x1a.dispatchEvent(lbx1x1x1e); 
正しく動作

page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js'); 
    setTimeout(InterLoginData, 90000); 


function InterLoginData(){ 
console.log ("Phantomjs.InterLoginData and Login."); 
page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
    //document.getElementById("password").focus(); 

    document.getElementById("login_btn").click(); 
    document.getElementById("login_btn").submit(); 

    $("login_btn").click(); 
    $("#login_btn").click(); 

    $("login_btn").submit(); 
    $("#login_btn").submit(); 


},ps,p); 

フロームグーグルクロームコンソール:

だからどちらかが動作しません。アイデアを投げてください。ありがとう。

+0

page.onErrorコールバックでエラーをチェックしてみてください。 – Vaviloff

+0

こんにちは! Vaviloffありがとう) – Pigrowant

答えて

0

明らかに、ボタンが押されました。しかし。 それはそのコードの後に​​判明:

page.evaluate(function(ps,p){ 
    var eps=ps; 
    var ep=p; 
    document.getElementById("username").value = eps; 
    document.getElementById("password").value = ep; 
},ps,p); 

ログイン名とパスワードのフィールドが満たされていないと考えページ。そしてそのページには、フィールドに記入するようにと尋ねるメッセージがありました。スクリーンショットではサイトが表示されませんでした。なぜなら、スクリーンキャプチャが短時間表示され、スクリーンキャプチャ時には既に消えていたからです。私はSlimerJSでコードを実行することでこれを見ることができました(ありがとう)。次のコードは必要に応じて動作し、入力するボタンが押されてメールに入りました。) ありがとうございます。

//************* 
var ps="PUT_LOGIN_HERE" 
var p="PUT_PASSWORD_HERE" 
//************* 

page.evaluate(function(){ 
    document.getElementById("username").focus(); 
}); 
page.sendEvent('keypress', ps); 


page.evaluate(function(){ 
    document.getElementById("password").focus(); 
}); 
page.sendEvent('keypress', p); 
page.sendEvent('keypress', "\n");//Enter 
関連する問題