attempt to use touch actions with unknown (web) element should use correct error
I recently saw a log with the following in it:
2023-08-24 09:32:07:494 - [HTTP] --> POST /wd/hub/session/54f235ff-2bd4-4872-853e-2d8fd5de66e2/actions
2023-08-24 09:32:07:494 - [HTTP] {"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":":wdc:1692894727303","element-6066-11e4-a52e-4f735466cecf":":wdc:1692894727303"}}]}]}
2023-08-24 09:32:07:494 - [debug] [W3C (54f235ff)] Calling AppiumDriver.performActions() with args: [[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":":wdc:1692894727303","element-6066-11e4-a52e-4f735466cecf":":wdc:1692894727303"}}]}],"54f235ff-2bd4-4872-853e-2d8fd5de66e2"]
2023-08-24 09:32:07:495 - [debug] [XCUITest] Executing command 'performActions'
2023-08-24 09:32:07:495 - [debug] [XCUITest] Received the following W3C actions: [
2023-08-24 09:32:07:495 - [debug] [XCUITest] {
2023-08-24 09:32:07:495 - [debug] [XCUITest] "id": "default mouse",
2023-08-24 09:32:07:495 - [debug] [XCUITest] "type": "pointer",
2023-08-24 09:32:07:495 - [debug] [XCUITest] "parameters": {
2023-08-24 09:32:07:495 - [debug] [XCUITest] "pointerType": "mouse"
2023-08-24 09:32:07:495 - [debug] [XCUITest] },
2023-08-24 09:32:07:495 - [debug] [XCUITest] "actions": [
2023-08-24 09:32:07:495 - [debug] [XCUITest] {
2023-08-24 09:32:07:495 - [debug] [XCUITest] "duration": 100,
2023-08-24 09:32:07:495 - [debug] [XCUITest] "x": 0,
2023-08-24 09:32:07:495 - [debug] [XCUITest] "y": 0,
2023-08-24 09:32:07:495 - [debug] [XCUITest] "type": "pointerMove",
2023-08-24 09:32:07:495 - [debug] [XCUITest] "origin": {
2023-08-24 09:32:07:495 - [debug] [XCUITest] "ELEMENT": ":wdc:1692894727303",
2023-08-24 09:32:07:495 - [debug] [XCUITest] "element-6066-11e4-a52e-4f735466cecf": ":wdc:1692894727303"
2023-08-24 09:32:07:495 - [debug] [XCUITest] }
2023-08-24 09:32:07:496 - [debug] [XCUITest] }
2023-08-24 09:32:07:496 - [debug] [XCUITest] ]
2023-08-24 09:32:07:496 - [debug] [XCUITest] }
2023-08-24 09:32:07:496 - [debug] [XCUITest] ]
2023-08-24 09:32:07:496 - [debug] [XCUITest] Preprocessed actions: [
2023-08-24 09:32:07:496 - [debug] [XCUITest] {
2023-08-24 09:32:07:496 - [debug] [XCUITest] "id": "default mouse",
2023-08-24 09:32:07:496 - [debug] [XCUITest] "type": "pointer",
2023-08-24 09:32:07:496 - [debug] [XCUITest] "parameters": {
2023-08-24 09:32:07:496 - [debug] [XCUITest] "pointerType": "touch"
2023-08-24 09:32:07:496 - [debug] [XCUITest] },
2023-08-24 09:32:07:496 - [debug] [XCUITest] "actions": [
2023-08-24 09:32:07:496 - [debug] [XCUITest] {
2023-08-24 09:32:07:496 - [debug] [XCUITest] "duration": 100,
2023-08-24 09:32:07:496 - [debug] [XCUITest] "x": 0,
2023-08-24 09:32:07:496 - [debug] [XCUITest] "y": 0,
2023-08-24 09:32:07:496 - [debug] [XCUITest] "type": "pointerMove",
2023-08-24 09:32:07:496 - [debug] [XCUITest] "origin": {
2023-08-24 09:32:07:497 - [debug] [XCUITest] "ELEMENT": ":wdc:1692894727303",
2023-08-24 09:32:07:497 - [debug] [XCUITest] "element-6066-11e4-a52e-4f735466cecf": ":wdc:1692894727303"
2023-08-24 09:32:07:497 - [debug] [XCUITest] }
2023-08-24 09:32:07:497 - [debug] [XCUITest] }
2023-08-24 09:32:07:497 - [debug] [XCUITest] ]
2023-08-24 09:32:07:497 - [debug] [XCUITest] }
2023-08-24 09:32:07:497 - [debug] [XCUITest] ]
2023-08-24 09:32:07:501 - [debug] [WD Proxy] Matched '/actions' to command name 'performActions'
2023-08-24 09:32:07:502 - [debug] [WD Proxy] Proxying [POST /actions] to [POST http://localhost:1904/session/C9347A3A-853B-445D-90D6-9DDA34FAF26C/actions] with body: {"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"touch"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"element-6066-11e4-a52e-4f735466cecf":":wdc:1692894727303","ELEMENT":":wdc:1692894727303"}}]}]}
2023-08-24 09:32:07:533 - [WD Proxy] Got response with status 404: {"value":{"error":"stale element reference","message":"The element identified by \":wdc:1692894727303\" is either not present or it has expired from the internal cache. Try to find it again","traceback":"(\n\t0 CoreFoundation 0x00000001a1b5a768 4FBDF167-161A-324C-A233-D516922C67E5 + 1218408\n\t1 libobjc.A.dylib 0x00000001b66217a8 objc_exception_throw + 60\n\t2 WebDriverAgentLib 0x0000000105376240 -[FBElementCache elementForUUID:resolveForAdditionalAttributes:andMaxDepth:] + 496\n\t3 WebDriverAgentLib 0x0000000105376024 -[FBElementCache elementForUUID:] + 80\n\t4 WebDriverAgentLib 0x000000010530d118 -[FBW3CActionsSynthesizer preprocessedActionItemsWith:] + 940\n\t5 WebDriverAgentLib 0x000000010530e03c -[FBW3CActionsSynthesizer eventPathsWithGestureAction:forActionId:error:] + 968\n\t6 WebDriverAgentLib 0x000000010530ea74 -[FBW3CActionsSynthesizer eventPathsWithActi...
2023-08-24 09:32:07:534 - [debug] [W3C] Matched W3C error code 'stale element reference' to StaleElementReferenceError
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] Encountered internal error running command: StaleElementReferenceError: The element identified by ":wdc:1692894727303" is either not present or it has expired from the internal cache. Try to find it again
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at errorFromW3CJsonCode (***/appium/1.22.3/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at ProxyRequestError.getActualError (***/appium/1.22.3/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at JWProxy.command (***/appium/1.22.3/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at runMicrotasks (<anonymous>)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at processTicksAndRejections (internal/process/task_queues.js:95:5)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at XCUITestDriver.proxyCommand (***/appium/1.22.3/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
2023-08-24 09:32:07:581 - [debug] [W3C (54f235ff)] at XCUITestDriver.performActions (***/appium/1.22.3/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/gesture.js:131:10)
2023-08-24 09:32:07:582 - [HTTP] <-- POST /wd/hub/session/54f235ff-2bd4-4872-853e-2d8fd5de66e2/actions 404 88 ms - 1319
This errored because the user tried to use an element reference for a web context element in a touch action, which is a native-only method. So the error is expected. But it should not be a stale element error. It should be a no such element error (according to the spec, if a driver doesn't recognize an element reference, this is what it should return.
The user was confused because stale element implies that the driver knows about the element but that it's no longer present. In actual fact, the (native) driver doesn't know anything about the (web) element.
For bonus points, we could detect a web element prefix (:wdc:) and provide an even more helpful error message body to the user to explain why they can't do what they're trying to do.
Alternatively, if we detect a web element inside a touch action, we could error with not yet supported, since that would essentially mean "touch actions don't work in web contexts"
It's unclear if we'd always be able to know for sure if the user is referencing a web element or not, though.
TouchAction support has been removed since v7 of the driver, so this is no longer relevant.
@jlipps Absolutely very good disclosure and knowledge to be understood by mobile test automation Developer. I am currently getting this error in the similar situation.
org.openqa.selenium.InvalidArgumentException: The XCUITest driver only supports W3C actions execution in the native context.
WebElement soldToFilterInput = waitingDriver.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#filterSoldTo.mobile-filter-soldto")));
Actions action=new Actions(driver);
System.out.println("Current contextName="+((IOSDriver)driver).getContext());// returns 'WEB_VIEW'
action.moveToElement(soldToFilterInput).click().sendKeys("UNITED PIPE & STEEL CORP").perform();
What I can do to rectify this issue ?
@PrasadNutalapati You need to use Actions API. Refer this example https://github.com/saikrishna321/VodQaAdvancedAppium/blob/master/src/test/java/com/appium/gesture/GestureTest.java#L75
@saikrishna321 Much appreciated Sai !
@jlipps
@saikrishna321
Gurus;
Here is the same issue as above, but in a different context.
I am running the same MobileWeb test on Android and iOS one after another.
With Android, the default context is 'CHROMIUM' and it is running the entire test just fine.
With iOS, even after shifting to WEBVIEW_1097.1 which is the WebView context, I am facing the following error messageorg.openqa.selenium.InvalidArgumentException: The XCUITest driver only supports W3C actions execution in the native context. when the below code was running
actions.moveToElement(categoryElm).click().build().perform();
Basically, it is moving to the Element 'categoryElm' and trying to click it, using the Actions class. I am not trying to do any gesture actions. I have to use this Actions class approach because other methods of click() are not working for my page. What is the coding approach for this issue can be overcome ?
Thanks a lot. --Prasad Nutalapati