Page 1 of 1

OptionTag not found in SelectTag although it is there

Posted: Wed May 14, 2014 10:36 am
by zero
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
optionTagToSearchFor.png
optionTagNotFound-Why.png
Thanks for any hint!

Re: OptionTag not found in SelectTag although it is there

Posted: Fri May 16, 2014 1:14 pm
by Support Team
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

Re: OptionTag not found in SelectTag although it is there

Posted: Mon May 19, 2014 9:45 am
by zero
That did it! :D Thank you Markus!

Roman