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
how to do WebPage Contains
Re: how to do WebPage Contains
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.
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...
Re: how to do WebPage Contains
// 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);
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);
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: how to do WebPage Contains
Hi,
It would be also possible to search for the element by using the following RxPath:
Regards,
Markus
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