Is there a way to test if a control in enabled or disabled, background colors etc? So if I grab a <asp:imagebutton control and I tell if it is enabled?
These are all attributes that get added to the rendered html tag (disabled="disabled" for instence). You will need to get a collection of the attributes (HtmlElementAttributeReader) for that element and then verify using those. Bellow is some code showing
how to get the HtmlElementAttributeReader for an element.
HtmlPage page = new HtmlPage("SomePage.aspx");
HtmlElement element = page.Elements.Find("ControlID");
HtmlElementAttributeReader reader = element.GetAttributes();
//Some common attributes are strongly typed properties
Assert.AreEqual("Expected", reader.Class);
//Other attributes are indexed through the collection
Assert.AreEqual("Expected", reader["disabled"]);
Matthew M. Osborn
http://blog.osbornm.com
http://www.codingqa.com
http://weblogs.asp.net/asptest
"Change the world or go home."
So this method only appears to work for a small number of properties.
Can you give an working example on how to find the property: naturalWidth inside of an Image Element?
Additionally, does any one have a clever way to use attributes to scan all the images on a page and see if they are loaded? I read that the naturalWidth will be set to 0 when an image doesn't load .. so I am trying to get that working.
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
I am not familiar with the "naturalWidth" attribute. You are saying that this attribute exists on the HTML DOM but you can't get to it when you do imageElement.GetAttributes() ? If so, then this sounds like a bug that we should to take a look at that.
srhone
Member
80 Points
23 Posts
Testing control properties
Feb 16, 2009 03:20 PM|LINK
Is there a way to test if a control in enabled or disabled, background colors etc? So if I grab a <asp:imagebutton control and I tell if it is enabled?
osbornm
Participant
914 Points
196 Posts
Microsoft
Re: Testing control properties
Feb 16, 2009 05:18 PM|LINK
Hey Srhone,
These are all attributes that get added to the rendered html tag (disabled="disabled" for instence). You will need to get a collection of the attributes (HtmlElementAttributeReader) for that element and then verify using those. Bellow is some code showing how to get the HtmlElementAttributeReader for an element.
http://blog.osbornm.com
http://www.codingqa.com
http://weblogs.asp.net/asptest
"Change the world or go home."
mcowan
Member
8 Points
42 Posts
Re: Testing control properties
Mar 28, 2009 02:29 AM|LINK
So this method only appears to work for a small number of properties.
Can you give an working example on how to find the property: naturalWidth inside of an Image Element?
Additionally, does any one have a clever way to use attributes to scan all the images on a page and see if they are loaded? I read that the naturalWidth will be set to 0 when an image doesn't load .. so I am trying to get that working.
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
farmas
Participant
1164 Points
259 Posts
Microsoft
Re: Testing control properties
Mar 28, 2009 08:00 PM|LINK
I am not familiar with the "naturalWidth" attribute. You are saying that this attribute exists on the HTML DOM but you can't get to it when you do imageElement.GetAttributes() ? If so, then this sounds like a bug that we should to take a look at that.
- Federico
mcowan
Member
8 Points
42 Posts
Re: Testing control properties
Mar 31, 2009 11:52 PM|LINK
So using Chrome - Inspect Element on an Image .. you can see the HTMLImageElement has a set of properties:
http://lh3.ggpht.com/_Y8FtTHDiOgY/SdKr_9Ol4ZI/AAAAAAAAAMM/YGjbra_plDM/s1024/Image_Properties.JPG
Also here is a web article talking about how to check naturalHeight using JavaScript:
http://javascript.royh.cn/img/naturalheight-2-0-naturalwidth.html
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
farmas
Participant
1164 Points
259 Posts
Microsoft
Re: Testing control properties
Apr 06, 2009 12:01 AM|LINK
Thanks! I've logged a bug for this. We'll look at it for the next refresh.
- Federico
mcowan
Member
8 Points
42 Posts
Re: Testing control properties
Apr 06, 2009 03:58 AM|LINK
Thanks alot. For reference here is another attempt to link images from my stupid google account.
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com