Winappdriver: How to simulate mouse click in C# appium unit test projece

Created on 2 Jan 2020  Â·  5Comments  Â·  Source: microsoft/WinAppDriver

How do I simulate mouse clicks on menu dropdowns in a C# Appium Unit test project?
Test setup Configuration:
• Visual Studio 2019 version 16.4.0
• Appium.WebDirver version 4.1.1
• Castle.Core version 4.4.0
• DotNetSeleniunExtras.PageObjects version 3.11.0
• MStest.TestAdapter version 2.0.0
• Newtonsoft.Jason version 12.03
• Selenium.Support version 3.141.0
• Selenium.WebDriver 3.141.0

I an earlier configuration I used the statement “session.Mouse.Click(appNameTitle.FindElementByName("AccessibleName").Coordinates)” to access menu items. Now I get a message this is obsolete. What is the correct syntax to simulate mouse clicks in the latest release of Appium?

Most helpful comment

I have used Selenium's Actions API. It's so Selenium/Appium can simulate complex interactions, but frankly I find it useful with WAD when things in the desktop app don't behave quite right. So E.G. (pseudo C# code):

Actions actions = new Actions(session);
actions.Click(appNameTitle.FindElementByName("AccessibleName")).Perform();

If the problem is that WAD is finding the element but not clicking in the right location, you can try something like:

// Usually mis-clicks are because the bounding box is bigger than click the area. So go in 15pixels from the top left corner to make sure we're hitting the button.
Actions actions = new Actions(session);
actions
   .MoveToElement(appNameTitle.FindElementByName("AccessibleName"), 15, 15)
   .Click()
   .Perform();

All 5 comments

Move to a lower version of Appium web driver version . 3.0.0.2.

Thanks for the response.
I know the I can use mouse click with a lower version of the web driver but I am getting an obsolete warning and would like to have everything with the latest versions without warnings.

thanks again
Bob

I have used Selenium's Actions API. It's so Selenium/Appium can simulate complex interactions, but frankly I find it useful with WAD when things in the desktop app don't behave quite right. So E.G. (pseudo C# code):

Actions actions = new Actions(session);
actions.Click(appNameTitle.FindElementByName("AccessibleName")).Perform();

If the problem is that WAD is finding the element but not clicking in the right location, you can try something like:

// Usually mis-clicks are because the bounding box is bigger than click the area. So go in 15pixels from the top left corner to make sure we're hitting the button.
Actions actions = new Actions(session);
actions
   .MoveToElement(appNameTitle.FindElementByName("AccessibleName"), 15, 15)
   .Click()
   .Perform();

Thanks for your reply

I am writing tests for a Windows Form Application and have not been able to simulate mouse clicks on the main menu’s dropdown commands using the latest versions of the Appium files (listed below) With earlier versions of the Appium files I used the session.Mouse.Click(appNameTitle.FindElementByName("dropdown_AccessableId ").Coordinates) statement it simulate mouse clicks . Your first suggestion works with the latest Appium files.

• Visual Studio 2019 version 16.4.3

• Appium.WebDirver version 4.1.1

• Castle.Core version 4.4.0

• DotNetSeleniunExtras.PageObjects version 3.11.0

• MStest.TestAdapter version 2.0.0

• Newtonsoft.Jason version 12.03

• Selenium.Support version 3.141.0

• Selenium.WebDriver 3.141.0

Thanks again

Bob Bryant

Email address: bob.bryant@pobox.com bob.[email protected]

Cell Phone: 602.430.2024

From: Mike Curn [mailto:[email protected]]
Sent: Monday, January 20, 2020 10:23 PM
To: microsoft/WinAppDriver
Cc: Bob Bryant; Author
Subject: Re: [microsoft/WinAppDriver] How to simulate mouse click in C# appium unit test projece (#1016)

I have used Selenium's Actions API. It's so Selenium/Appium can simulate complex interactions, but frankly I find it useful with WAD when things in the desktop app don't behave quite right. So E.G. (pseudo C# code):

Actions actions = new Actions(session);
actions.Click(appNameTitle.FindElementByName("AccessibleName")).Perform();

If the problem is that WAD is finding the element but not clicking in the right location, you can try something like:

// Usually mis-clicks are because the bounding box is bigger than click the area. So go in 15pixels from the top left corner to make sure we're hitting the button.
Actions actions = new Actions(session);
actions
.MoveToElement(appNameTitle.FindElementByName("AccessibleName"), 15, 15)
.Click()
.Perform();

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/microsoft/WinAppDriver/issues/1016?email_source=notifications&email_token=ABTIUOK76P63HKMLJCYD6QTQ62BCLA5CNFSM4KCGLFB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOQVXQ#issuecomment-576522974 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTIUOO4RKHL6XWSCV75TILQ62BCLANCNFSM4KCGLFBQ . https://github.com/notifications/beacon/ABTIUOIG5IHQICUE43Q4UITQ62BCLA5CNFSM4KCGLFB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOQVXQ.gif

This is an update on using actions as you suggested showing an odd behavior.

I have a “Tools” menu with an DropDown item “Auto Calculation”. I toggle “Auto calculation’s” checked property to enable and disable the application’s Auto Calculation. The first time I call the following code the state of the “Auto Calculation’s” checked property does not toggle. Later calls have always toggled the checked property. Also add a breakpoint to the first line in the following code makes it work on the first call.

     Actions actions = new Actions(session);

    // Click on main menu item “Tools’

     actions.Click(appNameTitle.FindElementByName("Tools")).Perform(); 

   // Click on Main menu ToolsDropDown item “Auto Calculation”

     actions.Click(appNameTitle.FindElementByName("Auto Calculation")).Perform();

So far the following code always works.

     // Click on main menu item “Tools’

     session.FindElementByName("Tools").Click(); //works

    // Click on Main menu ToolsDropDown item “Auto Calculation”

     actions.Click(appNameTitle.FindElementByName("Auto Calculation")).Perform();

Also I have not found any way to determine if “Auto calculation’s” checked property is checked in the test project.

Bob Bryant

Email address: bob.bryant@pobox.com bob.[email protected]

Cell Phone: 602.430.2024

From: Mike Curn [mailto:[email protected]]
Sent: Monday, January 20, 2020 10:23 PM
To: microsoft/WinAppDriver
Cc: Bob Bryant; Author
Subject: Re: [microsoft/WinAppDriver] How to simulate mouse click in C# appium unit test projece (#1016)

I have used Selenium's Actions API. It's so Selenium/Appium can simulate complex interactions, but frankly I find it useful with WAD when things in the desktop app don't behave quite right. So E.G. (pseudo C# code):

Actions actions = new Actions(session);
actions.Click(appNameTitle.FindElementByName("AccessibleName")).Perform();

If the problem is that WAD is finding the element but not clicking in the right location, you can try something like:

// Usually mis-clicks are because the bounding box is bigger than click the area. So go in 15pixels from the top left corner to make sure we're hitting the button.
Actions actions = new Actions(session);
actions
.MoveToElement(appNameTitle.FindElementByName("AccessibleName"), 15, 15)
.Click()
.Perform();

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/microsoft/WinAppDriver/issues/1016?email_source=notifications&email_token=ABTIUOK76P63HKMLJCYD6QTQ62BCLA5CNFSM4KCGLFB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOQVXQ#issuecomment-576522974 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTIUOO4RKHL6XWSCV75TILQ62BCLANCNFSM4KCGLFBQ . https://github.com/notifications/beacon/ABTIUOIG5IHQICUE43Q4UITQ62BCLA5CNFSM4KCGLFB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOQVXQ.gif

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomw93 picture tomw93  Â·  4Comments

hassanuz picture hassanuz  Â·  4Comments

ant-skelia picture ant-skelia  Â·  4Comments

sky205 picture sky205  Â·  3Comments

viji-123 picture viji-123  Â·  4Comments