Tuesday, September 11, 2012

Identification canonical tag is correct tag

Below program identify the canonical tag and open it the canonical url in new window and verified it is correct url



int result =0;
String url = selenium.getLocation();
if (selenium.isElementPresent("//link[@rel='canonical' and @href='" + (url) + "']"))
{
//System.out.println("Canonical tag present : " + selenium.getText("//link[@rel='canonical']"));
System.out.println("Canonical tag present : " + url);
selenium.openWindow(url, "url");
selenium.selectWindow(url);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.getHtmlSource().matches("^[\\s\\S]*404[\\s\\S]*$"))
System.out.println("Canonical tag is wrongly , gives 404 error for url"+url);
break; }
catch (Exception e) {
System.out.println("Canonical tag is correctly put");
};
Thread.sleep(1000);






No comments:

Post a Comment