目前,我在 Selenium IDE 中使用以下命令和目标来验证元描述的确切文本
verifyelementpresent : //meta[@name='description' and @content='description here']
我想检查元描述是否在 145 到 165 个字符之间,以查看它是否存在。这样当描述发生变化时,测试只会在描述少于 145 行或超过 165 行时失败(无论如何元描述都不能)
谁能帮我写下这个表达式?假设在内容下需要某种变量来检查..的长度
最佳答案
您可以使用 selenium 执行此 javascript:
document.evaluate("/html/head/meta[@name='description']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.content.length >= 144
&& document.evaluate("/html/head/meta[@name='description']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.content.length <= 166;
You need to subtract 1 from the initial value and add 1 at the end value because the content is returned with ""
它返回真或假。
或者您可以评估元描述内容并在您的应用中应用验证,例如
document.evaluate("/html/head/meta[@name='description']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.content
关于html - 使用 selenium IDE 检查是否存在元描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633890/