Forum Discussion

ANW's avatar
ANW
Contributor
15 years ago

.NET radPanelBar: how to find and click one of the items??

My applications make use of the Telerik radPanelBar, and I am having some issues trying to click on specific items in that object.



When running the Recorder in TC8.10, it just clicks on coordinates in the radPanelBar object. This is not really what I want, as the bar might change, and the coordinates to my menu item change too.



Now I have managed to locate the actual Item by iteriating through the radPanelBarObj.Items.item until I found one with the correct Caption. But I can't seem to find a Method, that then lets me activate/click on that item to open my tree view.



I have tried with Expand, Select, Focus, PerformClick. But none seem to work.



I have been using the following code to try this out:




function FindradPanelbarItem(radPanelbar: Olevariant; menuItemName: string): OleVariant;

var

  count, menuCount : integer;

  menuCaption : string;

  menuItem : Olevariant;

begin

  count := 0;

  menuCount := radPanelBar.Items.Count;

  repeat

    menuItem := radPanelBar.Items.item(count);

    menuCaption := menuItem.Caption.OleValue;

    inc(count);

  until

    (menuCaption = menuItemName) OR (count = menuCount -1);

  if (menuCaption = menuItemName) then

    result := menuItem

  else

    Log.error('Caption not found',

              'Menu item was not found with caption <' + menuItemName + '>');

end;







procedure Test1;


  var castorTEST : OleVariant;

  var splitContainer : OleVariant;

  var radPanelBar : OleVariant;

  var menuMobile : OleVariant;

begin

  castorTEST := Sys.Process('CastorTEST');

  splitContainer := castorTEST.CastorApp.WinFormsObject('toolStripContainer2').WinFormsObject('ToolStripContentPanel', '', 1).splitContainer1;

  radPanelBar := splitContainer.WinFormsObject('SplitterPanel', '', 1).navigationPane1.WinFormsObject('radPanelBar1');

//  radPanelBar.Click(77, 650);

  menuMobile := FindradPanelbarItem(radPanelBar,'Mobiltelefoni');

  menuMobile.PerformClick;

end;



Is there any way I can activate the specific item I need to use?? ... or am I forced to use coordinates for it?

2 Replies


  • Hi Anders,





    As I understand, you managed to retrieve a native object which represents the item you need to click and now you need to click the object with TestComplete. Since the object is native and it's not a TestComplete wrapper which has the Click action. If so, try using the following approach:

    1. Try using the control's native methods and properties to retrieve coordinates of the needed object.

    2. Use TestComplete's Click action to click the evaluated coordinates. In this case your test will be reliable and coordinates changes won't affect its behavior.


  • ANW's avatar
    ANW
    Contributor
    Thank the gods :) ... you are a life saver.



    Your advice helped, and I can now find the correct item coordinates in the radPanelbar, using the LocationToControl method, which gives me the X and Y coordinates of the item in the panel. Took me a while and some guess work to find it, as I can't seem to find any list or document online, that explains what each of the, 100 or so, methods actually do.



    I used this code to find and click on the correct item:




    menuMobile := FindradPanelbarItem(radPanelBar,'Mobiltelefoni');

    ControlX := menuMobile.locationToControl.X;

    ControlY := menuMobile.locationToControl.Y;

    radpanelbar.Click(ControlX,ControlY);




    But at least I found it.



    That should make my script reliable in the future too.