find a custom control

Oct 2, 2012 at 6:35 AM

I have a custom control <TI:ToolbarButton>

 


<
TI:ToolbarButton title="Save (Alt-S)" id="tbBtnSave" > <span id="buttonBorder" /> <img id="buttonImg" />

I tried to find that control but it can not work.

CUITe_HtmlCustom custom = bWin.Get<CUITe_HtmlCustom>("TI:ToolbarButton");
custom.SetSearchProperty("id", "tbBtnSave");

 

Coordinator
Oct 2, 2012 at 7:38 AM

Take a look at the CUITe_HtmlXml control for example to find out how to create a custom wrapper around custom controls here: http://cuite.codeplex.com/SourceControl/changeset/view/20526#334077

Oct 4, 2012 at 11:44 PM
Edited Oct 4, 2012 at 11:44 PM

Hi, I created a CUITe_HtmlToolbarButton class:

 

namespace CUITe.Controls.HtmlControls
{
    public class CUITe_HtmlToolbarButton : CUITe_HtmlCustom
    {
        private const string _tagName = "TI:ToolbarButton";

        public CUITe_HtmlToolbarButton()
            : base(_tagName)
        {
        }

        public CUITe_HtmlToolbarButton(string searchParameters)
            : base(_tagName, searchParameters)
        {
        }        
    }
}

 

And this is my code to find that control:

 CUITe_HtmlToolbarButton save = bWin.Get<CUITe_HtmlToolbarButton>();            
            save.SetSearchProperty("Id", "tbBtnSave");            
            save.Click();
But I can not find that control

Coordinator
Oct 5, 2012 at 12:27 AM

How does the Visual Studio Coded UI Test Recorder find the object?

Oct 5, 2012 at 12:34 AM

The Test Recorder find the object as a CUITe_HtmlImage. But this is the HTML source of that control:

<TI:ToolbarButton name="tbBtnSave" id="tbBtnSave" title="Save (Alt-S)" imgSrc="/gi/images/toolbar/image5a.png" imgDisabledSrc="/gi/images/toolbar/image5c.png" Disable="Disable" onclick="if(!this.disabled) {tbBtnSaveClick();}"  >tbBtnSave</TI:ToolbarButton>

Coordinator
Oct 5, 2012 at 12:44 AM

Please try the Visual Studio Coded UI Test Recorder to see what it defines the control properties to be and not the CUITe Object Recorder.

Oct 5, 2012 at 12:51 AM

The VS Coded UI Test Recorder defines the control properties which are: Control Type: Image; Id: buttonImg; TagName: IMG

Coordinator
Oct 5, 2012 at 12:55 AM

Ok, so if you try to use .Get<CUITe_HtmlImage>(...), does it work as expected?

Oct 5, 2012 at 1:07 AM

But I don't know how to fill the search properties, because there are many controls like this and all of them have the same properties that I mentioned before and they don't have ID properties.

Coordinator
Oct 5, 2012 at 1:27 AM

The last html sample you provided shows an id attribute.

Where did you get this html?

Is the value of the id attribute not unique for all controls on the page?

Oct 5, 2012 at 1:40 AM

When I use Developer Tools in IE to view the source, the HTML source of that control includes 3 tags:

<TI:ToolbarButton title="Save (Alt-S)" id="tbBtnSave" onclick="if(!this.disabled) {tbBtnSaveClick();}" name="tbBtnSave" imgDisabledSrc="/gi/images/toolbar/image5c.png" imgSrc="/gi/images/toolbar/image5a.png" Disable="Disable">
	<span id="buttonBorder" style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 1px; padding-left: 1px; padding-right: 1px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 1px;" width="0">
		<img id="buttonImg" style="position: relative;" src="/gi/images/toolbar/image5a.png" complete="complete"/>		

But when I right-click to view the page source of that web page, the HTML source is:

<TI:ToolbarButton name="tbBtnSave" id="tbBtnSave" title="Save (Alt-S)" imgSrc="/gi/images/toolbar/image5a.png" imgDisabledSrc="/gi/images/toolbar/image5c.png" Disable="Disable" onclick="if(!this.disabled) {tbBtnSaveClick();}"  >tbBtnSave</TI:ToolbarButton>
My web page has many image buttons and all of them have same id="buttonImg" but the control "TI:ToolbarButton" has different id.

Oct 5, 2012 at 2:03 AM

I found the solution. The tag name should be "ToolbarButton" not "TI:ToolbarButton".

Thanks for your help.

Coordinator
Oct 5, 2012 at 2:14 AM

Great!  I'm glad you found the solution! :)