0

WinObj either cannot be identified or is not visible when I run my script.

BUT when I click "Debug" button in the error message box that appears, then open the object repository and highlight in application the WinObj, the WinObj gets highlighted. And when I resume running my script, the script runs fine --- the error doesn't occur anymore.

How can I prevent this error from happening?

UPDATE: My code goes roughly like this:

    Public Function getText( winObjObject, textArray )
        Dim textHolder
        textHolder = winObjObject.GetVisibleText() '' this is where the error occurs
        textArray = Split(textHolder, vbCrLf)
    End Function
Xel
  • 540
  • 2
  • 8
  • 27

3 Answers3

0

For a more specific answer, I need to see some code. There could be a thousand reasons why this is occurring. But as a work around, you can prevent the error from happening by moving to manual error handling.

It sounds like you are letting the application perform error handling, so to move past this, at the top of your function/sub/segment of code, set "On Error Resume Next" and perform error handling manually. Take a look at the following links for more information on how to properly handle errors.

Link 1 Link 2 Link 3

Community
  • 1
  • 1
Rich
  • 4,134
  • 3
  • 26
  • 45
  • Hi @Rich --- Thanks. Kindly see my update for the code. – Xel Mar 10 '14 at 20:42
  • Hey Xel, so what it looks like is there is non-visible text and when your script executes it give you limited results because of this. Causing it to fail on and off. There are loads of complaints on how flimsy the GetVisibleText() method is. You should consider moving to GetRoProperty so that you can clearly identify which element you are trying to collect text off of. Read more -> http://qtp.blogspot.com/2008/05/qtp-gettoproperties-getroproperty.html – Rich Mar 10 '14 at 20:52
  • I don't think the GetVisibleText() is causing the error because when the error message box appears and I click the debug button on the error message box, open the object repository, do "highlight in application" to the the winobject, close the object repository and then click "Run", no error occurs and the GetVisibleText() succeeds and the script proceeds. Also, the getText() function is called repeatedly in my script and the error only occurs the first time getText() is called. – Xel Mar 10 '14 at 21:06
  • Then it's your activation of the winObjObject prior to calling the getText function during a specific segment of your master code. You should go through your code with a fine tooth code and verify that getText(object1, array) -- object 1 is activated everytime. – Rich Mar 10 '14 at 21:08
  • Thanks for the input @Rich. How can I activate my winObj? I've already tried winObjObject.Activate but Activate is not supported by WinObj. Is there any other way to activate the winobj? – Xel Mar 10 '14 at 21:15
  • Since it is indeed an object, make sure it has the statement "Set winObjObject = CreateObject("Whatever.App") so that it is activated as an object. – Rich Mar 10 '14 at 21:24
0

Hard to pinpoint the root cause causing your issue, but you could try to synchronize or initialize the object again before you get the text:

Public Function getText( winObjObject, textArray )
    Dim textHolder

    winObjObject.Sync()   ' Synchronizes the object i.e. wait until it is ready
    winObjObject.Init()   ' Re-initializes the object 

    textHolder = winObjObject.GetVisibleText() '' this is where the error occurs
    textArray = Split(textHolder, vbCrLf)
End Function

You have to play a bit with the two methods to see which one works.
Note: as I come from Web testing I do not know if sync is also a method on WinObjects.

AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47
0

The solution to my problem was "re-setting" the object before calling getText() function.

In code:

Set winObjObject = Browser("MyBrowser").Page("MyPage").WinObject("MyWinObject")
getText( winObjObject, textArray )
Xel
  • 540
  • 2
  • 8
  • 27
  • Try calling `winObjObject.RefreshObject` before calling `GetVisibleText`. This would eliminate the re-reference to the OR test object (which is good, since you pass the test object as an argument for a reason) and do the same thing (re-identify the GUI object the next time QTP accessed it). This might be required if the AUT changed the GUI´s object state after you last referenced it. `.RefreshObject` is undocumented, but its use is widespread meanwhile – TheBlastOne Mar 28 '14 at 20:01