Forum Discussion

olga_ulchina's avatar
olga_ulchina
Occasional Contributor
10 years ago
Solved

How to return object's mapped name (vbscript)

I mapped an element on a webpage, lets say it's Aliases.browser.page.button.

In my script I have a function which checks if this element is present on page.

Something like:



Function IsPresent (element)

....

'in case it does not exist log it's name

log.error element.MappedName

End Function



which I call like this:

IsPresent(Aliases.browser.page.button)



In case the element is not present I want to write to logs its Mapped Name (in our case it's Aliases.browser.page.button)



I know that there is method element.MappedName, but it returns a value only when element exists, if not, it returns something like "non-existent object". 



Is there a way to return mapped name even if element doesn't exist? Still I send it as a parameter in IsPresent()...





  • Hi Olga,



    A possible solution is to change IsPresent to accept the object name as a string. You can convert a string to an object using Eval.



    IsPresent("Aliases.browser.page.button")





    Function IsPresent(AliasStr)

      Dim element

      Set element = Eval(AliasStr)

      ...



      ' In case it does not exist log its name

      Log.Error AliasStr

    End Function



2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Olga,



    A possible solution is to change IsPresent to accept the object name as a string. You can convert a string to an object using Eval.



    IsPresent("Aliases.browser.page.button")





    Function IsPresent(AliasStr)

      Dim element

      Set element = Eval(AliasStr)

      ...



      ' In case it does not exist log its name

      Log.Error AliasStr

    End Function



  • olga_ulchina's avatar
    olga_ulchina
    Occasional Contributor
    Well, if there is no way to get String name from object, I accept the answer above, thanks