Forum Discussion

mikej411's avatar
mikej411
Occasional Contributor
9 years ago
Solved

How to verify whether a blinking cursor is currently inside of a text box

I am trying to verify that the text box gets the focus (the blinking cursor gets placed inside of it) after a certain action. I tried to use the Focused property, but it does not seem to work, or the object just doesnt have this property to begin with. Here is the code:


  mainWindow = Aliases.iexplore.IESA;  
  saveWindow = mainWindow.Find("ObjectIdentifier", "MainContent_saveFilterSetDialog_saveDialog", 50, true);
  saveWindowNameTextBox = saveWindow.Find("ObjectIdentifier", "*MainContent_*_sfsName", 25, true);
  if(saveWindowNameTextBox.Focused == true)
    Log.Message("The blinking cursor is inside of the name text box")
  else
    Log.Error("The blinking cursor is not inside of the name text box")

The logging window says "Waiting for Focused", then it fails and the log says "Unable to find the object with the specified properties"

 

Is there another way to accomplish this?

  • mikej411's avatar
    mikej411
    9 years ago

    Got it. Everything works now, thank you!

     

      var actualFocusedElement = Sys.Browser().Page("*BC/Report*").contentDocument.activeElement.id    
      if(aqString.Contains(actualElement, "saveDialog_tmpl_sfsName", 0, true))
        Log.Message("The blinking cursor is inside of the name text box")
      else
        Log.Error("The blinking cursor is not inside of the name text box")	

    I used the actual focused element's ObjectIdentifier (ID) and compared it against the expected ID, utilizing the activeElement jScript function.

14 Replies

  • --------------------------------------------------------------------------------------

    The log says "Unable to find the object with the specified properties"

    --------------------------------------------------------------------------------------

     

    It sounds like one of your finds isn't working.

     

    Need more info. Which object isn't found? You can't check anything until you find the right object ....

     

    We also have no details about the control (the textbox). What is the application written in? What type of TextBox is it? (I have about 6 or 7 different kinds in use in my Delphi application)

    • mikej411's avatar
      mikej411
      Occasional Contributor

      Hello, I will get that info. for you when I talk to the developer. In the meantime, I would like to add one more piece of info. The object is found and my Finds are correct, as in debug mode, the object is found correctly. While it tries to perform the If statement, the logging window says "Waiting for Focused". So maybe the object doesnt have this property?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        > The object is found [...]

        > maybe the object doesnt have this property?

        Both statements must be proved and this is the first thing that had to be done.

        I would recommend to:

        -- put a breakpoint at the

        if(saveWindowNameTextBox.Focused == true)

        line of code and run the test;

        -- when the test is stopped at the breakpoint, highlight the saveWindowNameTextBox variable and press Ctrl-F12 to call the Evaluate dialog;

        -- in the ensuing dialog, press the Inspect button and check the value of the Exists property. If its value is True, this means that the saveWindowNameTextBox object was found and you may proceed further. Value of False means that the object was not found and you must find out why it was not;

        -- if the saveWindowNameTextBox was found (its Exists property equals to True), then close the Inspector window and type saveWindowNameTextBox.Focused in the Evaluate dialog, press the Evaluate button and check the result.

         

        P.S. Comparison with the boolean values in the if() statement condition is not recommended programming style, so I would recommend to replace

        if(saveWindowNameTextBox.Focused == true)

        with

        if(saveWindowNameTextBox.Focused)