Automating the Clipboard on iOS and Android

     Now Appium has the built-in support for automating clipboard with support of following methods:
  • setClipboardText(“value”)
  • getClipboardText()

   To automate this scenario you have to use the latest Appium(>5.0.4) and Selenium(>3.9.1) versions. Following is the sample code:

public class ClipboardTest {  
    private String ANDROID_APP = “”;
    private String IOS_APP = “”;
    private String APPIUM_SERVER = “http://localhost:4723/wd/hub”;
    private By clipboardNav = MobileBy.AccessibilityId(“Clipboard Demo”);
    private By refreshClipboardBtn = MobileBy.AccessibilityId(“refreshClipboardText”);
    private By clipboardInput = MobileBy.AccessibilityId(“messageInput”);
    private By setTextBtn = MobileBy.AccessibilityId(“setClipboardText”);
    public void testClipboard_Android() throws IOException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(“platformName”, “Android”);
        capabilities.setCapability(“deviceName”, “Samsung”);
        capabilities.setCapability(“automationName”, “UiAutomator2”);
        capabilities.setCapability(“app”, ANDROID_APP);
        AndroidDriver driver = new AndroidDriver(new URL(APPIUM_SERVER), capabilities);
    public void testClipboard_iOS() throws IOException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(“platformName”, “iOS”);
        capabilities.setCapability(“platformVersion”, “11.3”);
        capabilities.setCapability(“deviceName”, “iPhone 7”);

        capabilities.setCapability(“app”, IOS_APP);
        IOSDriver driver = new IOSDriver(new URL(APPIUM_SERVER), capabilities);
    private void automateClipboard(AppiumDriver driver) {
        WebDriverWait wait = new WebDriverWait(driver, 5);
        try {
            String text = “Hello World”;
            ((HasClipboard) driver).setClipboardText(text);
            By clipboardText = MobileBy.AccessibilityId(text);
            Assert.assertEquals(driver.findElement(clipboardText).getText(), text);
            text = “Hello World Again”;
            try {
            } catch (Exception ign) {}
            Assert.assertEquals(((HasClipboard) driver).getClipboardText(), text);
        } finally {

Try to use the above code for your automation.

Reference: Appium Pro

make it perfect!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s