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:
Thanks for any hint!
OptionTag not found in SelectTag although it is there
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: OptionTag not found in SelectTag although it is there
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:
Regards,
Markus
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
That did it!
Thank you Markus!
Roman

Roman