I'm using WatiN for web testing, and am encountering issues caused by the fact that for the 'readonly' attribute of INPUT elements, WatiN is attempting to parse the value as a boolean, which as far as I can tell is incorrect, as the attribute should be written as follows:
<input readonly="readonly" />
When I try to access the TextField.Readonly
property from开发者_运维百科 WatiN at runtime, an error is thrown because WatiN attempts to parse 'readonly' as a boolean. I also encountered a similar issue with the 'selected' attribute of the <option>
element.
I find it hard to believe that nobody else has encountered these basic scenarios using WatiN which makes me think I am missing something obvious. Is there a known way to work around these issues or is this a known issue with WatiN?
This issue has to do with IE9 showing a page in IE9mode differs greatly from how IE9 in IE8mode (and older versions of IE) behaves. These problems have been fixed in WatiN 2.1
The syntax of readonly="readonly" that you mention is definitely correct according to w3c school and it looks like you have indeed found a bug.
Looking at /trunk/src/Core/TextField.cs in line 57 the code is
public virtual bool ReadOnly
{
get
{
var value = GetAttributeValue("readOnly");
return string.IsNullOrEmpty(value) ? false : bool.Parse(value);
}
}
so you should probably just change it to something like this, although I am not using the fancy ? and : syntax :-)
public virtual bool ReadOnly
{
get
{
string value = GetAttributeValue("readOnly");
if (value.ToLower() == "readonly")
{
return true;
}
else
{
return false;
}
}
}
精彩评论