How identify that button was clicked

Best practices, code snippets for common functionality, examples, and guidelines.
DenysKoval
Posts: 5
Joined: Fri Oct 27, 2017 4:07 pm

How identify that button was clicked

Post by DenysKoval » Fri Oct 27, 2017 4:44 pm

I have some problem.
I have some button on ui. Using SPY I identity that it is an enable and visible.
But when I do smth previosly, system eror popup is apear and block any other action.
Cursor pressed button(it is visible and enable),but actually it is not enable.
I want to use smth like try catch to throw new RanorexException.

public void operationWithText(string _value)
{
try
{
Text text = Text.FromPath(_controlPath);
if (text.Visible && text.WASCLICKED)
{
text.Focus();
text.DoubleClick();
Delay.Duration(2000);
Keyboard.Press("{LControlKey down}");
Keyboard.Press("{Akey}");
Keyboard.Press("{LControlKey up}");
Keyboard.Press(Keys.Back);
text.PressKeys(_value != null ? _value : "");
Keyboard.Press(Keys.Enter);
}
}
catch (RanorexException ex)
{
throw new RanorexException("Element with path '" + _controlPath + "' is not visible/enabled on screen.");
}
}

Thanks.

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: How identify that button was clicked

Post by McTurtle » Mon Oct 30, 2017 2:15 pm

Hello Denys,

After reading you post a few times, I am still failing at understanding the question :)

I do have a few questions myself:

1. Would you like to get rid of the system-error popup so that you can then click on the ui-button and continue with the test? If the popup is unexpected, then you should implement a popup watcher that clicks-away your popup: Handling unexpected Dialogs

2. Is the method operationWithText(string) what you are planning to use in order to determine if the system-error popup is present? It would be much easier to help you with your code, if you would post a Ranorex snapshot of the system-error popup and a Ranorex snapshot of the ui-element that you would actually like to click. Please do create both snapshots and attach them to your next post. You can create the snapshots by following the instructions under the following link: How to Create a Ranorex Snapshot

Furthermore, what are you planning to do after the exception has been thrown? From your post it seems that you actually want the test to fail if the system-error popup has appeared.

Please do describe the test case in more detail and post the two snapshots so that we may help you better :)

Regards,
McTurtle