2

Nightwatch.jsを使用してプロジェクトを作成しました。このプロセスでは、dev環境でのチェックが行われ、テストメールをGmailアカウントに送信します。プロセスはGmailに行き、ログインして正しいメールをクリックします。Gmail内で要素を見つけることができません

アプリケーションに送信されたURLを取得しようとしています(パスワードのリンクを忘れた)し、ブラウザを正しいURLに送信しようとしています。

browser 
    .useXpath() 
    .getText("string(//*[text()[contains(text(),'RetrievePassword')]])",function(result) 
    { 
    console.log(result.log) 
    }) 

私はこのエラーを取得:

ERROR: Unable to locate element "" using: xpath

をしかし、私は、リンクをクリックしてナイトウォッチを伝えるとき、それは問題でそうします

問題は、私は次のコードを使用する場合であります。何か案が?

URLは次のようになります。

https://test.website.com/Secure/RetrievePassword.aspx?code=123456789

答えて

2

私はあなたのXPathセレクタが間違っていると思います。代わりに//*[contains(text(),'RetrievePassword')]を使用した場合、正常に動作するはずです。ここでは基本的な例である:

HTML(index.htmlの

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Nightwatch</title> 
</head> 
<body> 
    <a href="https://test.website.com/Secure/RetrievePassword.aspx?code=123456789">https://test.website.com/Secure/RetrievePassword.aspx?code=123456789</a> 
</body> 
</html> 

はJavaScriptgmail.js

module.exports = { 
    'Gmail': function (browser) { 
    browser 
     .url('http://localhost:8000/index.html') // Change this if needed 
     .waitForElementPresent('body', 1000) 
     .useXpath() 
     .getText("//*[contains(text(),'RetrievePassword')]", function (res) { 
     console.log(res.value); 
     }) 
     .end(); 
    } 
}; 

コマンド

nightwatch -t tests/gmail.js 
関連する問題