Sometimes, to check if the targeted webpage has been completely opened (instead of receiving an instance of the 404 page not found error), it is enough to see if the page contains some specific text (usually, the text is unique for the given page).
In this recipe we will consider an example of such verification.
Launch the Internet Explorer and open the following site: http://smartbear.com/.
On the main page, locate any text, which will be unique namely for the given page (in our example, we will be using the Tools for your needs text).
To check if the targeted text is available on a page, it is necessary to perform the following actions:
isTextPresent
function that executes the verification:function isTextPresent(element, text) { return aqString.Find(element.contentText, text) > -1; }
isTextPresent
function (replace the highlighted text with the one you have located in the beginning of this recipe):function testVerifyText()
{
var br = Sys.Browser("iexplore");
var page = br.Page("http://smartbear.com/");
var form = page.Form("aspnetForm");
Log.Message(isTextPresent(form, "Tools for your needs"));
}
testVerifyText
function, the result in the log will be True.The contentText
property contains the whole text of the element, including related child elements. This property is analogous to those of innerText
and textContent
; however, unlike those, it works equally in all the browsers.
In our example, we have used the contentText
property for the whole of the page (that is, for the element that corresponds to the page), which means we have obtained all the available text on-site.
Similarly, we can obtain all the text of any other web-element (that is, Panel
or TextNode
).
18.216.44.143