Page 1 of 1

Changing Object Types

Posted: Wed Jun 30, 2010 9:09 am
by jainaakash
Hi Team,

How do we change object type from one to another. For example, I would like to change an String to a RXPath type. Actually, I am getting the below error:
=======
Unexpected exception occured: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Ranorex.Core.RxPath'.
=======

Dim cntryContainer As Ranorex.Container = repo.ContainerSelectbox.countryListContainer
Dim strCountryName As String = "AUSTRALIA"
Dim cntryXPath
cntryXPath = "/listitem[@accessiblename='"& strCountryName &"']"

Dim lstItem As ListItem = cntryContainer.FindSingle(Of ListItem)(cntryXPath)
lstItem.Click()

I tried converting String cntryXPath to RxPath like below, but didnt work.
Dim newrxPath as Ranorex.Core.RxPath = ConvertFromString(cntryXPath)
I got the below error which suggests that this is not the correct way of using it:
"Reference to a non-shared member requires an object reference. (BC30469) -"

Can anyone please help.

Thanks and Regards,
Aakash

Re: Changing Object Types

Posted: Wed Jun 30, 2010 10:40 am
by Support Team
You can just assign a string to an RxPath variable or use the RxPath constructor to create a new instance:
Dim path1 As RxPath = "myPath1"
Dim path2 As RxPath = new RxPath("myPath2")
Dim path1Element As Unknown = Host.Local.FindSingle(path1)
Dim button As Button = Host.Local.FindSingle("pathToButton")
I copied your code into a VB project and it worked just fine (except for the ConvertFromString method, I really don't know what that method should do...).

Regards,
Alex
Ranorex Team

Re: Changing Object Types

Posted: Wed Jun 30, 2010 2:22 pm
by jainaakash
Thanks Alex,

The below worked:
Dim path2 As RxPath = new RxPath("myPath2")

Regards,
Aakash