Wierd whitespace character in RanoreXpath

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
mdavidson
Posts: 3
Joined: Thu Jun 30, 2011 3:49 pm

Wierd whitespace character in RanoreXpath

Post by mdavidson » Mon Oct 10, 2011 3:06 pm

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.
You do not have the required permissions to view the files attached to this post.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Wierd whitespace character in RanoreXpath

Post by Ciege » Mon Oct 10, 2011 6:09 pm

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
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

mdavidson
Posts: 3
Joined: Thu Jun 30, 2011 3:49 pm

Re: Wierd whitespace character in RanoreXpath

Post by mdavidson » Tue Oct 11, 2011 9:01 am

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

mdavidson
Posts: 3
Joined: Thu Jun 30, 2011 3:49 pm

Re: Wierd whitespace character in RanoreXpath

Post by mdavidson » Tue Oct 11, 2011 9:41 am

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! :)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Wierd whitespace character in RanoreXpath

Post by Support Team » Tue Oct 11, 2011 9:50 am

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