Call a code module with parameter

Ask general questions here.
shellyhu
Posts: 9
Joined: Mon Sep 29, 2014 9:07 am

Call a code module with parameter

Post by shellyhu » Tue Nov 11, 2014 9:26 am

Hi

I have a code module as follows. I use a parameter in RxPath

Code: Select all

Dim _Ele As String = ""
		<TestVariable("D498FD3D-F9B3-4CED-B43E-6B5E5C530484")> _
		Public Property Ele As String
			Get
				Return _Ele
			End Get
			Set(ByVal value As String)
				_Ele = value
			End Set
		End Property

                Public Sub aaaa
        	       _Ele = "1234"
                        Dim _RawText As Ranorex.RawText = Nothing
			Dim found As Boolean = Host.Local.TryFindSingle(Of Ranorex.RawText) _
			("/form[@title~'home']/rawtext[@rawtext~$_Ele]", 10000, _RawText)
			report.Info(found.ToString)
		End Sub

I run this code, the specified RxPath can be found.

But I call this sub in other code module, It can't find the specified RxPath.

Code: Select all

               Dim _aa As New bbbb
           	_aa.aaaa
Does the parameter lose efficacy if it is called in other code module ?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Call a code module with parameter

Post by Support Team » Thu Nov 13, 2014 2:42 pm

Hi Shellyhu,

The following code should work for you:
Dim _Ele As String = ""
      <TestVariable("D498FD3D-F9B3-4CED-B43E-6B5E5C530484")> _
      Public Property Ele As String
         Get
            Return _Ele
         End Get
         Set(ByVal value As String)
            _Ele = value
         End Set
      End Property

                Public Sub aaaa
                  Ele = "1234"
                        Dim _RawText As Ranorex.RawText = Nothing
         Dim found As Boolean = Host.Local.TryFindSingle(Of Ranorex.RawText) _
         ("/form[@title~'home']/rawtext[@rawtext~"+Ele+"]", 10000, _RawText)
         report.Info(found.ToString)
      End Sub
The problems seems that Ranorex doesn't know that "$Ele" is actually a variable when you execute the method from another module, so it should be okay when you use " "+Ele+" " instead.

In case "aaaa" is a recording I would use the following code:
Dim _aa As bbbb = bbbb.Instance
            _aa .aaaa()
and I would highly recommend using meaningful names for your classes and methods.

Regards,
Markus
.
Image

shellyhu
Posts: 9
Joined: Mon Sep 29, 2014 9:07 am

Re: Call a code module with parameter

Post by shellyhu » Mon Nov 17, 2014 7:15 am

Hi,

Thank you for your suggestion.

I use your method to run my scrip, but it also can't find the element. Even though run it without calling it in other code module.

I try it on two computers, the same result happens.

My Ranorex version is 5.0.2.
(If I use the latest version, there is another problem. So I haven't upgraded. Link: http://drafttest.ranorex.com/forum/exce ... t5413.html )

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Call a code module with parameter

Post by Support Team » Tue Nov 18, 2014 1:45 pm

Hi Shellyhu,

When the element cannot be found at all it is most likely a problem with the used RxPath.
Could you therefore please check if you use the right RxPath to identify the specific element?
I tested the code I provided on my machine with another RxPath and everything worked well, so the method should be fine.

Regards,
Markus
.
Image