我使用 Nightwatch.js 创建了一个项目。该过程在我们的开发环境中执行检查(工作正常)并最终将测试电子邮件发送到 Gmail 帐户。然后该过程将转到 Gmail,登录并单击正确的电子邮件。
我试图获取发送到应用程序的 URL(忘记密码链接)并将浏览器发送到正确的 URL。
问题是当我使用以下代码时:
browser
.useXpath()
.getText("string(//*[text()[contains(text(),'RetrievePassword')]])",function(result)
{
console.log(result.log)
})
我收到此错误:
错误:无法定位元素“”使用: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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句