我想检查描述元标记是否有任何值但不确定如何操作。
试过这个但没有运气:
browser.verify.element("meta[name=description]").attribute('content').not.equals('');
任何帮助表示感谢,谢谢!
答案 0 :(得分:0)
使用Selenium protocol "element":
browser.element('css selector', '#advanced-search', function(result){
if(result.status != -1){
//Element exists, do something
} else{
//Element does not exist, do something else
}
});
简单的Javascript解决方案:
if(document.querySelector("meta[name=description]")){
if(document.querySelector("meta[name=description]").getAttribute("content") === "Description of the webpage")
console.log("meta description with content 'Description of the webpage' found");
// do something
}
else{
console.log("meta description not found");
// do something
}

<meta name="description" content="Description of the webpage"/>
&#13;
来源:Nightwatchjs: how to check if element exists without creating an error/failure/exception, How to check for existing meta tag before generating a new one with javascript (or jquery)?