如何验证 Nightwatch 中段落元素中的文本?

问题描述

我在页面上有一个文本,我必须验证该文本是否存在。元素的 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'); 我确保所有空格都得到了照顾。 非常感谢任何帮助。

解决方法

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

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

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

Checking inner text