Forum Discussion

ct_biji's avatar
ct_biji
Occasional Contributor
14 years ago

Issue while logging into an application

There is an application which i have to login using an user name and password.both the fields are text controls with same object name but different indexes after multiple execution an error pops up suggesting that the object doesnot exist even though it is present in the name mapping.

i have attached an image file to show the application GUI.

I am attaching the code as well is there any other way to log in or to add these objects seperately to that they exist .

1 Reply


  • Hi Biji,





    As I understand, you need to identify an edit box which does not have any unique properties. If so, try using the following code which can be used to identify an object with a specific class by caption of a label located near the object:







    function getControl(pnlParent, lblText, classNameSubstr)

    {

      // Find the label

      var lbl = pnlParent.FindChild("wText", lblText, 20000); // If the wText property does not work, try using the Text property or any other property which contains the label's text





      // Find the control located to the right of the label





      // Set the starting X-coordinate point in the coordinates of the parent panel

      var x = lbl.Left + lbl.Width;

      var control = null;





      for (var i = 0; i < 100; i++)

      {

        // Move 5 pixels to the right  

        x += 5;

      

        // Get the object located in the current position

        var curObj = Sys.Desktop.ObjectFromPoint(x, lbl.Top + lbl.Height / 2)





        // Check whether the current object is a text box

        if (curObj.WndClass.indexOf(classNameSubstr) > -1)

        { // The current object is the needed text box

          control = curObj;

          break;

        }

      }

      

      return control;

    }





    function test()

    {

      // TODO: Assign the container object to the pnlGeneral variable

      

      // The text of the label located to the left of the needed control

      var labelText = "My Value:";  

      // A class name substring which identifies the control as the needed text edit control (modify the substring if necessary) 

      var controlClass = "TextEdit" 

        

      // Try to get the control located to the right of the label with the specified text

      var txtMyValue = getControl(pnlGeneral, labelText, controlClass);

        

      if (txtMyValue != null)

      {

        Log.Message("Object found successfully! See Remarks for more information.", "FullName: " + txtMyValue.FullName);

      }

      else

      {

        Log.Error("An object with the '" + controlClass + "' class name located near the '" + labelText + "' label was not found.");

      }

    }