Accessing object method with InvokeRemotely

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Tnimni
Posts: 49
Joined: Thu Jan 02, 2014 4:03 pm

Accessing object method with InvokeRemotely

Post by Tnimni » Tue Apr 08, 2014 11:17 am

Hi,

please see the attached code:

Code: Select all

		public static object OpenDropdownButton(System.Windows.Forms.Control control, object input)
		{
			DevExpress.XtraEditors.DropDownButton theButton = control as DevExpress.XtraEditors.DropDownButton;
			
			theButton.ShowDropDown();
			
			return null;
		}
			
		public static object showDropDownButtonContextMenu(this Ranorex.Button button)
		{
			Ranorex.Control control = button.Element.Parent.As<Ranorex.Control>();
			control.InvokeRemotely(OpenDropdownButton);
			return null;
		}
as you can see i'm sending a Ranorex.Button to showDropDownButtonContextMenu
and than i cast it into Ranorex.Control and perform control.InvokeRemotely(OpenDropdownButton)

which than execute the method on the UI control.

The thing i DON'T understand is why i have to do

Code: Select all

 button.Element.Parent.As<Ranorex.Control>(); 
in order for it to cast the item and not just

Code: Select all

button.As<Ranorex.Control>();
when doing the latter it returns null.

i would like to point out that the button is xpath in the repository is [Edit: i forgot to mention that this path is for the button and it sits under a higher level in the repository which contains the form]

Code: Select all

container[@controlname='panelClient']/container[@controlname='scMain']/container[@caption='Panel2']/container[@controlname='grpTerms']/element[@controlname='btnCreateTerm']/button[@accessiblename='Create']
so to my understanding going to

Code: Select all

button.Element.Parent
will actually go to the ontainer[@controlname='grpTerms'] which is weird, or am i mistaken and it goes to element[@controlname='btnCreateTerm']?
also i have tried to define the button in the repository as an element (ommiting the button[@accessiblename='Create'] from Xpath) and than i taught i will not need to go to

Code: Select all

button.Element.Parent
but it still returns null if i don't go to the elemnt parent.

Regards,

Tnimni

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: Accessing object method with InvokeRemotely

Post by mzperix » Tue Apr 08, 2014 4:46 pm

Hi Tnimni,

button.Element is referring to the button element itself. So button.Element.Parent is referring to the direct parent element: element[@controlname='btnCreateTerm'].

So what your code did, is you selected the parent element of the button, then you created a Control type adapter for it. It could create, since the parent element is element type, and it has the required capabilities.

The code you tried and did not work is because you tried to create a Control type adapter to the button itself. It returned null, since the button did not have the Control's required capabilities.

I think the reason you still has to use the

button.Element.Parent is you still set the adapter type to Ranorex.button. Try to make it more general, like Ranorex.Element.

Hope this helps.

Regards,
Zoltán

Tnimni
Posts: 49
Joined: Thu Jan 02, 2014 4:03 pm

Re: Accessing object method with InvokeRemotely

Post by Tnimni » Wed Apr 09, 2014 7:05 pm

mzperix wrote:Hi Tnimni,

button.Element is referring to the button element itself. So button.Element.Parent is referring to the direct parent element: element[@controlname='btnCreateTerm'].

So what your code did, is you selected the parent element of the button, then you created a Control type adapter for it. It could create, since the parent element is element type, and it has the required capabilities.

The code you tried and did not work is because you tried to create a Control type adapter to the button itself. It returned null, since the button did not have the Control's required capabilities.

I think the reason you still has to use the

button.Element.Parent is you still set the adapter type to Ranorex.button. Try to make it more general, like Ranorex.Element.

Hope this helps.

Regards,
Zoltán
Many thanks!