Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get identification property from object when object doesn't exist on page
#1
Not Solved
hi all,

i'm trying to get the "name" property of an object. the object may or may not be present on the page and for my testing purposes it doesn't matter. when i try the following and the object is not present on the page i get an "Cannot identify the object...Verify that this object's properties match an object currently displayed in your application."

Code:
Browser("Browser").Page("Page").WebEdit("Control").GetTOProperty("name")

all i need to do is get at the object's name, which is already saved inside the object repository and as i said above, i don't care if the object exists or not.

i was hoping there would be a way to retrieve an object's property from its object repository without needing it to be present on the page.

does anyone have a solution?

thanks!
Reply
#2
Not Solved
'The following example retrieves an object repository's objects and properties,
'looks for specific test objects using several methods, and copies a test object
'to another object repository.

Code:
Dim ImageObj, PageObj, RepositoryFrom, RepositoryTo

Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
Set RepositoryTo = CreateObject("Mercury.ObjectRepositoryUtil")

RepositoryFrom.Load "C:\QuickTest\Tests\Flights.tsr"
RepositoryTo.Load "E:\Temp\Tests\Default.tsr"
Function EnumerateAllChildProperties(Root)
'The following function recursively enumerates all the test objects directly under
'a specified parent object. For each test object, a message box opens containing the
'test object's name, properties, and property values.
Code:
Dim TOCollection, TestObject, PropertiesCollection, Property, Msg

    Set TOCollection = RepositoryFrom.GetChildren(Root)

    For i = 0 To TOCollection.Count - 1
            Set TestObject = TOCollection.Item(i)
            Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
            Set PropertiesCollection = TestObject.GetTOProperties()

            For n = 0 To PropertiesCollection.Count - 1
                Set Property = PropertiesCollection.Item(n)
                Msg = Msg & Property.Name & "-" & Property.Value & vbNewLine
            Next
            MsgBox Msg

EnumerateAllChildProperties TestObject
    Next

End Function

Function EnumerateAllObjectsProperties(Root)
'The following function enumerates all the test objects under a specified object.
'For each test object, a message box opens containing the test object's name,
'properties, and property values.
Code:
Dim TOCollection, TestObject, PropertiesCollection, Property, Msg

    Set TOCollection = RepositoryFrom.GetAllObjects(Root)

    For i = 0 To TOCollection.Count - 1
        Set TestObject = TOCollection.Item(i)
                    Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine

            Set PropertiesCollection = TestObject.GetTOProperties()
            For n = 0 To PropertiesCollection.Count - 1
                Set Property = PropertiesCollection.Item(n)
                Msg = Property.Name & "-" & Property.Value & vbNewLine
            Next

        MsgBox Msg
    Next

End Function

Function RenameAllImages(Root)
'The following function sets a new name for all image test objects under a specified object.
Code:
Dim TOCollection, TestObject, PropertiesCollection, Property

    Set TOCollection = RepositoryTo.GetAllObjectsByClass("Image")

    For i = 0 To TOCollection.Count - 1
            Set TestObject = TOCollection.Item(i)
            RepositoryTo.RenameObject (TestObject, "Image " & i)
            RepositoryTo.UpdateObject TestObject
    Next

End Function

Function RemoveAllLinks(Root)
'The following function recursively enumerates all the test objects under a specified object.
'It looks for all test objects of class Link and removes them from their parent objects.
Code:
Dim TOCollection, TestObject, PropertiesCollection, Property

    Set TOCollection = RepositoryFrom.GetChildren(Root)

    For i = 0 To TOCollection.Count - 1
            Set TestObject = TOCollection.Item(i)
            TOClass = TestObject.GetTOProperty("micclass")

         If TOClass = "Link" Then
                RepositoryFrom.RemoveObject Root, TestObject
            End If

        EnumerateAllChildProperties TestObject
    Next

End Function
Reply
#3
Not Solved
hi vinod123! thanks for your solution!

however, i've already tried this solution in the past on another project. qtp is terrible with object repository locks. if you load one it "locks" it and most of the time when you try and run the script again it gives a "general runtime error". even opening the repository directly in the qtp repository manager confirms it's locked. plus, there's not even a close() or release() function on the repository object.

would there be a way to make qtp fallback to the object repository when using GetTOProperty() with the object doesn't exist on the page?

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File Chooser on Chrome doesn't work - UFT 15.0.1 Nenna Rosa 1 3,304 10-31-2020, 01:16 PM
Last Post: Ankur
  Enabling Smart Identification for SAP Gui object prasanna.kale5@gmail.com 0 839 12-05-2019, 08:04 PM
Last Post: prasanna.kale5@gmail.com
  Exist and Visible Are True When Objects Aren't There - Is there A Better Way? zunebuggy 3 2,709 04-24-2018, 02:12 PM
Last Post: Ankur
  Time Delay issue with Exist mv8167 11 23,955 06-19-2017, 02:56 PM
Last Post: grosorg
  Object identification is taking too much time JACKSPARROW 0 1,586 01-17-2017, 11:08 AM
Last Post: JACKSPARROW

Forum Jump:


Users browsing this thread: 1 Guest(s)