gpt4 book ai didi

javascript - 无法在 Gmail 中找到元素

转载 作者:行者123 更新时间:2023-11-29 21:04:47 26 4
gpt4 key购买 nike

我使用 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 单击该链接时,它会毫无问题地执行此操作。有什么想法吗?

URL 如下所示:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com