Page 1 of 1

Wierd whitespace character in RanoreXpath

Posted: Mon Oct 10, 2011 3:06 pm
by mdavidson
Hello all,

I have this issue with my AUT whereby the inner text value of a certain element contains a whitespace character that I am unable to account for in my tests.

The following is an example of the code used to produce the RanoreXpath for the element:

Code: Select all

DivTag divValue = Repository.VosDomXpath + "//div[@id~'dropdown']//div[@innertext='" + value + "']";
When the value 'Next Week' is passed in the value parameter, a RanoreXpath like this is produced:

Code: Select all

/dom[@domain='46.51.166.61']//div[@id~'dropdown']//div[@innertext='Next Week']
Problem is, an exception is thrown because this RanoreXpath yields no results... when I use the Spy tool to bring up the available values for the innertext attribute of the div I am looking for, the value 'Next Week' appears. This therefore produces the exact same RanoreXpath as the one shown above.

Why were these seemingly identical RanoreXpaths yielding different results?

To find out, I popped them both in notepad++ and used the 'Show All Characters' button (the one that reveals carriage return and whitespace characters) to see if there was any difference. At first there was not, however when I changed the character encoding from ANSI to UTF-8, notepad++ revealed this wierd whitespace character inbetween 'Next' and 'Week'. A screenshot of notepad++ revealing this is attached.

This character is obviously being produced by the AUT. With that in mind, How do I account for this? I need to pass in different values on the fly i.e. I cannot hard code this whitespace character in my tests...

Cheers in advance.

Re: Wierd whitespace character in RanoreXpath

Posted: Mon Oct 10, 2011 6:09 pm
by Ciege
You can use a RegEx expression in your XPath. Check out the RegEx information in the User Guide: http://www.ranorex.com/support/user-gui ... xpath.html

Re: Wierd whitespace character in RanoreXpath

Posted: Tue Oct 11, 2011 9:01 am
by mdavidson
The aforementioned code is contained within a method, it's signature looks like this:

Code: Select all

public static void ChangeSearchFilter(string filter, string value, bool search = true) { ... }
Typical usage would therefore be:

Code: Select all

ChangeSearchFilter("Date Period", "Next Week");
ChangeSearchFilter("Location", "Bridge of Earn");
ChangeSearchFilter("Day of Week", "Tuesday");
The tests are parameterized and these particular values are typically entered in by non-technical users. Also, as seen above, not all values passed in have whitespace in them.

Obviously I can do the regex within the method; how would I go about acheiving this?

My initial thought would be to use regex to match any whitespace characters against the supplied value and replace them with some regex that would do the same in the RanoreXPath.

this is fine, I was just wondering if there was a better way of doing this?

Cheers

Re: Wierd whitespace character in RanoreXpath

Posted: Tue Oct 11, 2011 9:41 am
by mdavidson
I have overcome this issue with the following code (as suggested above):

Code: Select all

DivTag divValue = Repository.VosDomXpath + "//div[@id~'dropdown']//div[@innertext~'" + value.Replace(" ", @"\s") + "']";
It was more straightforward than I had anticipated! :)

Re: Wierd whitespace character in RanoreXpath

Posted: Tue Oct 11, 2011 9:50 am
by Support Team
Hi,

you can also simply copy/paste the string form Notepad++ to your assignment if you don't want to use the mentioend regexp.

Regards,
Tobias
Support Team