This project is read-only.

Search Control By ClinetID

Apr 13, 2011 at 3:58 AM

I need your expert advice for following case. Since the tools is great  ,I am enjoy using it.

In order to get control by ID  

 

 

 

 

 

 

 but HtmlControl.Id is changed from server to server.

eg

from

ctl00_m_g_13e8351d_9c38_41f0_932f_27ff69f56b96_ctl00_txtAmt

to

b4477e41_e18c_45c0_a334_831472604af3middle GUID  changes.

========================

I did following work around to solve this issue  Which is not always right .

ctl00_m_g_13e8351d_9c38_41f0_932f_27ff69f56b96_ctl00_txtAmtTotal.

txtAmt is contain in txtAmtTotal as well.

this._control.SearchProperties.Add(sKey, sValue, PropertyExpressionOperator.Contains);

========================

I prefer to search id end with 'txtAmt' and 'txtAmtTotal' respecitvely .

Would like to know poissible to seach this way ?

  Thanks ahead .

kmyothwe.

 this._control.SearchProperties.Add(HtmlControl.PropertyNames.Id, sValue);

 

// this._control.SearchProperties.Add(sKey, sValue, PropertyExpressionOperator.Contains);

Apr 18, 2011 at 9:05 AM

This is a very strange case! The following code can be used as a work around. Convert it into a function and placing it in the object repository will give you better re-usability and modularity.

            UITestControlCollection uicol = pgSearch.txtAmt.UnWrap().FindMatchingControls();
            foreach (UITestControl uiobj in uicol) {
                if (uiobj.GetProperty("id").ToString().EndsWith("txtAmt"))
                {
                    Mouse.Click(uiobj);
                }
            }

For the above code to work, you should continue to use this._control.SearchProperties.Add(sKey, sValue, PropertyExpressionOperator.Contains);.

However, I feel you should sit with the dev/architect and convince them to change the way ids are being dynamically generated, if at all it is possible. :)