Page 1 of 1

how to do WebPage Contains

Posted: Thu Apr 03, 2014 6:12 pm
by rj905
I am trying to find out if the entire web page contains a certain string value. This is easily done in selenium with a call like

driver.getPageSource().Contains("some value");

Can anyone let me know if this is possible in Ranorex?

Thanks,
Rich

Re: how to do WebPage Contains

Posted: Fri Apr 04, 2014 1:41 pm
by krstcs
The HTML structure requires that all text be part of an HTML object (divtag, texttag, etc.).

You should be able to bring up the page with the text, spy out/track the object that contains the text and add it to the repository.

From that point, all you have to do is drag that repository object up to the action table in your recording module and select the validation you want to perform from the drop-down that appears. I would suggest validate exists and then validate attribute (innertext, etc.) equals/contains with the text you are looking for.



If your developers are moving the object around, it may be harder, but they probably still use a standard structure for the object in question, so you can just trim the XPath to match.

Re: how to do WebPage Contains

Posted: Thu Apr 10, 2014 4:29 pm
by rj905
// C# way to do it.

WebDocument webDoc = "/dom[@domain='my url']";
String source = webDoc.GetHtml();
int count = 0;
int n = 0;

while ((n = source.IndexOf(keyword, n, StringComparison.InvariantCulture)) != -1)
{
n += keyword.Length;
++count;
}

Validate.IsTrue (count > 3);

Re: how to do WebPage Contains

Posted: Fri Apr 11, 2014 1:15 pm
by Support Team
Hi,

It would be also possible to search for the element by using the following RxPath:
var root= repo.yourRootElement;
        	root.Self.Find(".//*[?'some value']", new Duration(30000));
Please note that this can take a while since Ranorex has to search through the whole element tree (beginning from the root element) to find an element with an attribute set to the specific string.

Regards,
Markus