question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selecting an item from context menu

See original GitHub issue

Hi,

I am using Appium on Windows 10. I am testing classical windows application built with .NET. I am trying to select item from context menu that appears after I right-click edit box (through Appium’s java-client). My code and logs are below.

Before I tried Appium I have been experimenting with native Windows functions from User32.dll and I have noticed that once context menu appears I am unable to send click events nor key events to it although I can get the window handle for the menu. I found online that this may have something to do with privileges or “integrity” level of applications (“UIAccess”) but so far I wasn’t able to bypass that. I tried running in elevated mode and changing local security policies.

Also, I was unable to use findElementByAccessibilityId(“177”) which should give me access to “Select All” item in system’s context menu for text box, so I couldn’t use that either (element not found exception).

Am I doing something wrong or is this an issue that needs to be addressed either in documentation or code fixes?

WebElement elem = driver.findElement(By.xpath("/Window/Edit[2]"));
Actions action = new Actions(driver);
action.contextClick(elem).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

The action fails and the following is logged to the console (I have replaced machine name, app’s full path etc. with …):

Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: [object Object] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: '...', ip: '...', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: io.appium.java_client.windows.WindowsDriver
Capabilities [{app=...\\WindowsFormsApp1.exe, javascriptEnabled=true, platformName=WINDOWS, deviceName=WindowsPC, platform=WINDOWS}]
Session ID: 0c29a348-7dbd-4404-af8b-9cab4525a6cc
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
	at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
	at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
	at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1)
	at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)
	at org.openqa.selenium.remote.RemoteKeyboard.sendKeys(RemoteKeyboard.java:38)
	at org.openqa.selenium.interactions.SendKeysAction.perform(SendKeysAction.java:53)
	at org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:36)
	at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:641)
...

The Appium server logs this:

[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] ==========================================
[WinAppDriver] [STDOUT] POST /wd/hub/session/E5958A79-2AF5-4623-9CAE-2F352BF23BF3/keys HTTP/1.1
[WinAppDriver] [STDOUT] Accept: */*
[WinAppDriver] [STDOUT] Connection: keep-alive
[WinAppDriver] [STDOUT] Content-Length: 17
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT] Host: 127.0.0.1:4736
[WinAppDriver] [STDOUT] User-Agent: appium
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] {"value":[""]}
[WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error
[WinAppDriver] [STDOUT] Content-Length: 133
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] {"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
[MJSONWP] Encountered internal error running command:  {"jsonwp":{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
    at JWProxy.proxy$ (../../../lib/jsonwp-proxy/proxy.js:152:13)
    at tryCatch (...\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (...\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (...\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (...\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/0c29a348-7dbd-4404-af8b-9cab4525a6cc/keys 500 9 ms - 186

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eascqtcommented, Nov 8, 2017

Hi @timotiusmargo

After your suggestion I have modified the code to look like this:

        DesiredCapabilities appCapabilities = new DesiredCapabilities();
        appCapabilities.setCapability("platformName", "Windows");
        appCapabilities.setCapability("deviceName", "WindowsPC");
        appCapabilities.setCapability("app", "Root");
        WindowsDriver ds = new WindowsDriver(new URL("http://127.0.0.1:4723/wd/hub"), appCapabilities);
        ds.findElementByAccessibilityId("177").click();

That did the trick! “Select All” from context menu was clicked. Thank you very much for helping out.

To answer your question, the log above is generated when I attempted to insert key events (ARROW_DOWN) with original code that is on the top of this thread. The idea was to show context menu and then move highlight to the next item in the menu by simulating arrow keys.

Anyways, I have all I need now to write my test. Thank you for support!

0reactions
hassanuzcommented, Nov 14, 2017

Thanks for reporting back. Closing ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get Selected Item from Context Menu - wpf
Is there any way I can get the selected item in the context menu? Normally one would load the model classes (Image in...
Read more >
Finding items in the File Explorer context menu
Open the context menu. To open the context menu, right-click (or select and hold) on a file or folder in File Explorer ....
Read more >
Using the context menu
To perform an action on one or several objects in an action list, you can use the context menu: Select an object by...
Read more >
Add or Delete Items from Right-Click Context Menu in ...
Look for the item you want to remove “Open With”, right click it and select “Delete” from the list. This will remove the...
Read more >
Selecting a context menu item by text value
Re: Selecting a context menu item by text value​​ try typing the letters of the text. If it works you can simulate the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found