setClipboardText() is not working with Appium 1.21.0 + iOS 14.6

I’ve updated to Appium 1.21.0 and clipboard is not working anymore, I’m using real iOS devices with iOS 14.6

[HTTP] --> POST /wd/hub/session/649aaa25-bdbe-4adf-bae3-7cc94255746f/appium/device/set_clipboard
[HTTP] {“content”:“dGVzdA==”,“contentType”:“plaintext”}
[debug] [W3C (649aaa25)] Calling AppiumDriver.setClipboard() with args: [“dGVzdA==”,“plaintext”,null,null,null,“649aaa25-bdbe-4adf-bae3-7cc94255746f”]
[debug] [XCUITest] Executing command ‘setClipboard’
[XCUITest] Proxying to WDA with an unknown route: POST /wda/setPasteboard
[debug] [WD Proxy] Proxying [POST /wda/setPasteboard] to [POST http://127.0.0.1:8102/session/B29494F1-7949-47D8-85FD-8956D5901246/wda/setPasteboard] with body: {“content”:“dGVzdA==”,“contentType”:“plaintext”}
[debug] [WD Proxy] Got response with status 200: {“value”:null,“sessionId”:“B29494F1-7949-47D8-85FD-8956D5901246”}
[debug] [W3C (649aaa25)] Responding to client with driver.setClipboard() result: null
[HTTP] <-- POST /wd/hub/session/649aaa25-bdbe-4adf-bae3-7cc94255746f/appium/device/set_clipboard 200 37 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/649aaa25-bdbe-4adf-bae3-7cc94255746f/appium/device/get_clipboard
[HTTP] {“contentType”:“plaintext”}
[debug] [W3C (649aaa25)] Calling AppiumDriver.getClipboard() with args: [“plaintext”,“649aaa25-bdbe-4adf-bae3-7cc94255746f”]
[debug] [XCUITest] Executing command ‘getClipboard’
[XCUITest] Proxying to WDA with an unknown route: POST /wda/getPasteboard
[debug] [WD Proxy] Proxying [POST /wda/getPasteboard] to [POST http://127.0.0.1:8102/session/B29494F1-7949-47D8-85FD-8956D5901246/wda/getPasteboard] with body: {“contentType”:“plaintext”}
[debug] [WD Proxy] Got response with status 200: {“value”:"",“sessionId”:“B29494F1-7949-47D8-85FD-8956D5901246”}
[debug] [W3C (649aaa25)] Responding to client with driver.getClipboard() result: “”
[HTTP] <-- POST /wd/hub/session/649aaa25-bdbe-4adf-bae3-7cc94255746f/appium/device/get_clipboard 200 23 ms - 12

(For iOS real devices) Apple security preferences require the WebDriverAgentRunner application to be in foreground in order to be able to receive the system clipboard content. Otherwise an empty string is always returned. Consider using Activate App and Background App to change the foreground application.

https://appium.io/docs/en/commands/device/clipboard/get-clipboard/#description

The log doesn’t indicate that you’ve put WDA into the foreground. So I’m forced to guess that this is the problem. More here:

Thanks for your answer, but I do not need to get clipboard content, I need to set clipboard content and then paste it elsewhere, and it had worked before update. Are these Apple security preferences came with iOS 14.6 ?

i guess it same. WDA app just does not have access to clipboard while in background. no matter get or set.

@wreed you and @Aleksei were totally right. I’ve tried to put WDA to foreground before set clipboard and now it works. Strange that it worked before, but anyway thank you both for your advice.

1 Like