我使用 Nightwatch.js 创建了一个项目。该过程在我们的开发环境中执行检查(运行良好),并最终将测试电子邮件发送到 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
但是当我告诉 Nightwatch 单击该链接时,它会毫无问题地执行此操作。有什么想法吗?
网址如下所示:
https://test.website.com/Secure/RetrievePassword.aspx?code=123456789
最佳答案
我认为您的 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>
JavaScript (gmail.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
关于javascript - 无法在 Gmail 中找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44546492/