nightwatchjs 元标记检查是否不为空

nightwatchjs meta tag check if is not empty

我想检查描述元标记是否有任何值,但不知道该怎么做。

已经尝试过但没有成功:

browser.verify.element("meta[name=description]").attribute('content').not.equals('');

感谢任何帮助,谢谢!

使用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"/>

来源:Nightwatchjs: how to check if element exists without creating an error/failure/exception