2017-09-11 2 views
0

Je voudrais vérifier si la balise meta description a une valeur, mais je ne sais pas comment le faire.nightwatchjs meta tag cocher si n'est pas vide

ont essayé cela, mais pas de chance:

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

toute aide appréciée, merci!

Répondre

0

Utilisation du 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 
    } 
}); 

Plaine solution 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"/>

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

+0

J'ai fait: this.verify.equal (1,2); fonctionne mais mauvais je crois. – serkan

+0

@ serkandemirel0420 Je ne suis pas très familier avec nightwatch.js ni sélénium mais je pense que je vous ai indiqué dans la bonne direction. Vous pouvez consulter les sources dans ma réponse et poursuivre la recherche. – PredatorIWD