【问题标题】:Unable to locate element inside Gmail无法在 Gmail 中找到元素
【发布时间】:2017-11-16 16:58:37
【问题描述】:

我使用 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

【问题讨论】:

    标签: javascript xpath selenium-webdriver nightwatch.js e2e-testing


    【解决方案1】:

    我认为您的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2019-06-23
      相关资源
      最近更新 更多