OptionTag not found in SelectTag although it is there

Class library usage, coding and language questions.
zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

OptionTag not found in SelectTag although it is there

Post by zero » Wed May 14, 2014 10:36 am

I want to check a HTML select list if it contains certain elements and check their index in the list (the order in which they appear to the user). Unfortunately, the element that I am searching for is not found, although it is clearly in the list. Why is this?

I debugged the code and checked the values:
list.png
The select list with it's options. Note that OptionTag:AT is there.
list.png (53.32 KiB) Viewed 903 times
optionTagToSearchFor.png
The option to search for.
optionTagToSearchFor.png (40.83 KiB) Viewed 903 times
optionTagNotFound-Why.png
The negative search result, which I do not understand.
optionTagNotFound-Why.png (24.63 KiB) Viewed 903 times
Thanks for any hint!

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

Re: OptionTag not found in SelectTag although it is there

Post by Support Team » Fri May 16, 2014 1:14 pm

Hi,

The problem here is that the Validation will only return true when it is the same instance of the object. The same holds for the Contains and the IndexOf method. It will just return true respectively the right index when it is the exact same instance of the object.
In order to check if the two OptionTag instances represent/target the same live element you need to check if the TagValues or the Elements are equal.
So you could use the following code instead:
Validate.AreEqual(austria.Element, optionList[0].Element); // austria should be the first element in the list
//OR
Validate.AreEqual(austria.TagValue, optionList[0].TagValue);
I hope this helps you to redesign your code.

Regards,
Markus
.
Image

zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

Re: OptionTag not found in SelectTag although it is there

Post by zero » Mon May 19, 2014 9:45 am

That did it! :D Thank you Markus!

Roman