Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to dismiss the keyboard in appium using Java?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.48k
    Comment on it

    When we enter any text in textbox through sendKeys() then after entering the text also the keyboard is not dismissed. If we want to locate the element on the screen then the element could not be located, so to locate the element on screen, the keyboard should be dismissed. Appium provides a method to dismiss the keypad once we have entered the text.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","GT-7582");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("appPackage", "com.whatsapp");
    capabilities.setCapability("appActivity", "com.whatsapp.Main");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
    WebElement frameLayout = driver.findElement(By.id("android:id/action_bar_container"));
    List textView = frameLayout.findElements(By.className("android.widget.TextView"));
    System.out.println(textView.size());
    textView.get(1).click();
    driver.findElement(By.id("android:id/search_src_text")).sendKeys("Kanishka");
    driver.findElement(By.id("android:id/menu_btn")).click();
    

    In the above code after entering the text "Kanishka" in the search box, the keyboard is not dismissed and so the menu button cannot be located. .

    driver.hideKeyboard();
    

    We will use the method hideKeyboard() to hide the keyboard after entering the text

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: