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"
cntryXPath = "/listitem[@accessiblename='"& strCountryName &"']"
Dim lstItem As ListItem = cntryContainer.FindSingle(Of ListItem)(cntryXPath)
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,
Ask general questions here.
3 posts • Page 1 of 1
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...).