initialize not existing button in user code

Ask general questions here.
bkruse
Posts: 38
Joined: Tue Jul 20, 2010 12:19 pm

initialize not existing button in user code

Post by bkruse » Wed Feb 25, 2015 1:15 pm

Hi,

I have a toolbar and want to click a button on it.
Depending on window size, the toolbar might hide that button and show a little "overflow" button at its end, which then shows a little popup menu with the hidden toolbar buttons.
So far no problems (click initial button if visible/found, else click overflow button and click popup menus button).

To ease this for multiple toolbar buttons, I aim to create a user code method. I want to pass the button/buttonInfo object to it and let it do the work. So roughly like this:

Code: Select all

public void Mouse_Click_ToolbarButton_test()
{
    //Button button = repo.a.b.ButtonInfo.CreateAdapter<Ranorex.Button>(false);
    Button button = repo.a.b.Button;    // Ranorex checks the button now, how to suppress that?
    RepoItemInfo buttonInfo = repo.a.b.ButtonInfo;
    Mouse_Click_ToolbarButton(button, buttonInfo);
}

public void Mouse_Click_ToolbarButton(Button targetButton, RepoItemInfo targetButtonInfo)
{
    // do something here with targetButton
}
Problem: in line Button button = repo.a.b.Button; Ranorex tries to find the button in the GUI, which is not true at this time (in our situation here). Even the CreateAdapter alternative (commented above) or using the full RxPath in the code behaves the same way.

Probably I misunderstood something of the Ranorex mechanics here. So how can I get a Button/Repository object without having it to exist? Or how to suppress the check for existence?

Thanks and Bests, Björn

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

Re: initialize not existing button in user code

Post by Support Team » Thu Feb 26, 2015 11:06 am

Hi Björn,

I’d suggest checking the existence of the RepoItemInfo object.
If this does exist you can simply create a new button with the CreateAdapter method and click this button.
If the object does not exist you need to click on your overflow button and then create a new button.

You can for instance use the following code to achieve your plan
public void CheckButtonAndClick(Ranorex.Core.Repository.RepoItemInfo argument1)
			{
				if(argument1.Exists(1000)) //Please adapt this timeout in order to fit your needs
				{
					Button button = argument1.CreateAdapter<Button>(false);
					button.Click();
				}
				else
				{
					// Put your code to click on the overflow button here
					// for example :
					//repo.Overflow.click();
					Button button = argument1.CreateAdapter<Button>(false);
					button.Click();
				}
			}
Regards,
Markus (S)
.
Image