I would like to check if the description meta tag has any value but not sure how to do it.
Have tried this but no luck:
browser.verify.element("meta[name=description]").attribute('content').not.equals('');
any help appreciated, thanks!
I would like to check if the description meta tag has any value but not sure how to do it.
Have tried this but no luck:
browser.verify.element("meta[name=description]").attribute('content').not.equals('');
any help appreciated, thanks!
Using the 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
}
});
Plain Javascript solution:
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"/>
Sources: 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)?