I needed to test some elements that were being added to certain pages on a web site. I already had some tests that looked for visible page content but no tests that check for elements only visible in the page source.
I am using the json script format used by selenium builder in this example, to do this i used this:
{
"type": "verifyElementAttribute",
"locator": {
"type": "xpath",
"value": "//link"
},
"attributeName": "hreflang",
"value": "blah"
},
The important bit is the xpath value of ‘//link’. I was looking for this string in the page source:
<link rel="alternate" href="awebsite" hreflang="blah" />
The xpath finds the link tag and once this is found i could then test that the hreflang element had the value of ‘blah’. I can also using the same method test the other parts of the link rel tag.
Hope this help you if your looking to do a similar thing!