how to do WebPage Contains

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
rj905
Posts: 2
Joined: Thu Apr 03, 2014 6:05 pm

how to do WebPage Contains

Post by rj905 » Thu Apr 03, 2014 6:12 pm

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: how to do WebPage Contains

Post by krstcs » Fri Apr 04, 2014 1:41 pm

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.
Shortcuts usually aren't...

rj905
Posts: 2
Joined: Thu Apr 03, 2014 6:05 pm

Re: how to do WebPage Contains

Post by rj905 » Thu Apr 10, 2014 4:29 pm

// 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);

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: how to do WebPage Contains

Post by Support Team » Fri Apr 11, 2014 1:15 pm

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
.
Image