简体   繁体   中英

“Object cannot be identified” or “Object not visible” Run Error in QTP?

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

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

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.

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM