Dashboard > Selenium > ... > Contributed User-Extensions > assertMetaRobotTags
Selenium Log In View a printable version of the current page.
assertMetaRobotTags
Added by Martin Ballhatchet, last edited by Martin Ballhatchet on May 23, 2007  (view change)
Labels: 
(None)

What is it?

This extension allows you to easily check the "index" and "follow" Meta Robot tags for a page.

How to add it to selenium:

1. Add the following code into the 'user-extensions.js' file:

user-extensions.js
Selenium.prototype.assertMetaRobotTags = function(thisIndex, thisFollow) 
	{
		// Grab meta robots element, and compare the tags
		var expectedIndex = thisIndex.toLowerCase();
		var expectedFollow = thisFollow.toLowerCase();
		var actualIndex;
		var actualFollow;

		//var xpathCommand = "xpath=//meta[contains(@name,\"robots\")]";
		var xpath = "//meta[contains(@name,\"robots\") and (contains(@content, \"index\") or contains(@content, \"follow\"))]";
		var xpathCommand = "xpath=" + xpath;
		
		try 
		{
			var element = this.page().findElement(xpathCommand);
		}
		catch (e) 
		{
			var message = 'Test failed:\n' + "Meta Robots Tag not found"; 
			LOG.error(message);
			Assert.fail(message);
			return;
		}

		var content = element.getAttribute("content").toLowerCase();
		actualIndex = (content.indexOf("noindex")>-1)
			? "noindex"
			: (content.indexOf("index")>-1) 
				? "index"
				: "undefined";
		
		actualFollow = (content.indexOf("nofollow")>-1)
			? "nofollow"
			: (content.indexOf("follow")>-1) 
				? "follow"
				: "undefined";
		
		LOG.info("Actual Index: " + actualIndex + " - Actual Follow: " + actualFollow);
		Assert.matches(expectedIndex, actualIndex);
		Assert.matches(expectedFollow, actualFollow);
	};

Example:

Sample Selenium code:
open http://www.google.com
verifyMetaRobotTags noindex follow

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators