Wednesday, 20 March 2013

How to store & assert HTML-meta-tag?


<META> tag is a special HTML tag that provides information about a Web page. Metadata will not be displayed on the page, but will be machine parsable.

Unlike normal HTML tags, meta tags do not affect how the page is displayed. Instead, they provide information such as,
  • who created the page(author), 
  • how often it is updated, 
  • what the page is about(page description), and 
  • which keywords represent the page's content. 

Many search engines use this information when building their indices. This is how it looks:

<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Ståle Refsnes">
<meta charset="UTF-8">
</head>

Note: <meta> tag always goes inside the <head> element.

Store & Assert <meta> tag 'Description' content:

1. Use the command, "storeAttribute" for storing contents present inside the <meta> tag.
2. Insert the xpath //meta[@name='description']@content in Target field.
3. Now store the value and print it.

storeAttribute  |  //meta[@name='description']@content  |  variable
echo  | ${variable}


Java code for store and assert <meta> tag description contents:

String variable= driver.findElement(By.xpath("//meta[@name='description']")).getAttribute("content");
System.out.println(variable);
assertEquals("your text", variable);

3 comments: