【问题标题】:How to verify the text in a paragraph element in Nightwatch?如何验证 Nightwatch 中段落元素中的文本?
【发布时间】:2021-09-13 01:04:52
【问题描述】:

我在页面上有一个文本,我必须验证该文本是否存在。元素的 html 是 <p class="subfooter__text" data-v-79ab1348=""> The Tesla is part of the <a href="//www.xyz.com/" target="_blank" rel="noopener nofollow">Automobile</a> publishing family.</p>

需要验证的文字是“特斯拉是汽车出版家族的一部分”。问题是,当断言全文时断言失败,但断言“汽车”或“出版系列”或“汽车出版系列”时它确实通过了。对于 href 标记之前的文本,断言永远不会通过。

这是代码部分browser.assert.containsText('p.subfooter__text', 'The Tesla is part of the Automobile publishing family'); 我确保所有空格都得到了照顾。 非常感谢任何帮助。

【问题讨论】:

    标签: javascript selenium nightwatch.js nightwatch


    【解决方案1】:

    您的断言看起来是正确的。我唯一能看到的就是句子末尾的点。

    browser.assert.containsText('p.subfooter__text', 'The Tesla is part of the Automobile publishing family.');
    

    以下是我将您的代码添加到 HTML 页面并提取内部文本时的屏幕截图。

    【讨论】:

      猜你喜欢
      • 2021-04-15
      • 1970-01-01
      • 2023-02-09
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多