Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click on a "pane" using UI automation library?

We have an application in which I need to click on a Pane. I tried to use the following code, which I use to click on a button, but it gave Unsupported pattern exception.

InvokePattern click_pattern = (InvokePattern)adjust_button.GetCurrentPattern(InvokePattern.Pattern); click_pattern.Invoke();

Is there any other way to do it?

like image 320
Tejas Avatar asked Dec 06 '25 14:12

Tejas


1 Answers

Even though the object is clickable, depending on how the click is being handled internally, you may not necessarily be able to use the InvokePattern to perform a click. That appears to be the case here.

As an alternative, you can use some code to move the mouse cursor over the pane and issue a click using P/Invoke. Something like this:

private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;

[DllImport("user32.dll")]
private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

...
...

AutomationElement paneToClick;

...
...

Cursor.Position = paneToClick.GetClickablePoint();
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new IntPtr());
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new IntPtr());
like image 186
Chaser324 Avatar answered Dec 08 '25 06:12

Chaser324



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!