Finding Meta Tag in Page Source

We have a site which contains a meta tag on the page which goes under head section.

" meta name=“siteStatus” content=“Running” " (HTML removed)

I tried using the script below to validate “Running”

var By = $driver.By;
var assert = require(‘assert’);
var URL = “URL Name”;
var textToFind = “Running”;

// Load the New Relic home page
$browser.get(URL).then(function(){

// Get full page Text and check for existance of string
var pageText = $browser.findElement($driver.By.tagName(“head”)).getText()
.then(function(head){
var headLower = head.toLowerCase();
assert.ok(headLower.indexOf(textToFind) != -1,"Text “+ textToFind+ " Running not found in body”);
});
});

But i always get results as not found even if it’s present inside meta tag

var pageText = $browser.findElement($driver.By.tagName(“head”)).getText()
.then(function(head){

Should get replaced with

return $browser.findElement($driver.By.tagName(“head”)).getText()
.then(function(head){

1 Like
  • more. Please post latest script, mask the actual URL plz

Hi @parikshit.singh1 - You cannot perform this using the FindElement as detailed on this post:

http://grokbase.com/t/gg/webdriver/155wx8zwjv/how-to-get-the-content-tags-that-reside-in-head-head-of-a-webpage

Hi stefan_garnham

So do we have any other function definded that can validate the meta tag under head section.

Hi stefan_garnham

Do we have any other function which can search the meta tag in head section.

The post I linked to specifies the Selenium method to use. You can match this in the Synthetics Scripted Browser reference documentation

1 Like