0

How to clear pre-filled text box value using java in appium?

I have tried all possible solution available on Internet but not works for me.

I have used .clear() and .sendKey() both method and it's working fine in Android 6.0 and below version. but it does not working after Android 7.0 or above version.

Here is my code,

driver.findElement(By.id("com.example.appName:id/text_user_name")).clear(); 
driver.findElement(By.id("com.example.appName:id/text_user_name")).sendKeys("Automation");

I'm trying to automate my android application using below configuration:

Appium-Desktop 1.7.2.

selenium-java 3.8.1

selenium-server 3.8.1

java-client 5.0.4

BhavinD.
  • 435
  • 5
  • 18

1 Answers1

0

Yes, I also ran on this in few occasions, this is not most beautiful code, but works quite good in a pinch:

public void clearTxt(WebElement element) throws Exception{
      element.click();
      element.sendKeys(Keys.CONTROL + "A"); //select all
      element.sendKeys(Keys.DELETE);          
}

or

element.sendKeys("") 

or

Actions navigator = new Actions(driver);
navigator.click(element)
    .sendKeys(Keys.END)
    .keyDown(Keys.SHIFT)
    .sendKeys(Keys.HOME)
    .keyUp(Keys.SHIFT)
    .sendKeys(Keys.BACK_SPACE)
    .perform();

one of this should be enough...

Kovacic
  • 1,473
  • 6
  • 21