0

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!

serkan
  • 6,885
  • 4
  • 41
  • 49

1 Answers1

0

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)?

Luka Čelebić
  • 1,083
  • 11
  • 21
  • I did : this.verify.equal(1,2); works but bad I believe. – serkan Sep 11 '17 at 08:53
  • @serkandemirel0420 I am not very familiar with nightwatch.js nor selenium but I think I pointed you in the right direction. You can check out the sources in in my answer and research further. – Luka Čelebić Sep 11 '17 at 08:55