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
Changing Object Types
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Changing Object Types
You can just assign a string to an RxPath variable or use the RxPath constructor to create a new instance:
Regards,
Alex
Ranorex Team
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
-
- Posts: 48
- Joined: Thu Jun 10, 2010 12:06 pm
Re: Changing Object Types
Thanks Alex,
The below worked:
Dim path2 As RxPath = new RxPath("myPath2")
Regards,
Aakash
The below worked:
Dim path2 As RxPath = new RxPath("myPath2")
Regards,
Aakash