I have my login screen in app now. Each time the app is launched in screen the mobile number is pre filled with the older text.
I just want to know I have tried:
WebElement element2 = appiumDriver.findElement(By.xpath(element));
element2.sendKeys(Keys.CONTROL + "a");
element2.sendKeys(Keys.DELETE);
This normally happens when the opened screen in your app, is a "WebView".
When faced with similar problem, I followed the below steps:
Below, is the code that might just help you out in resolving your problem:
WebElement ele = driver.findElement(By.xpath("//Locator of the textfield")); //Locating the textfield int characters_to_delete = ele.getAttribute("value").length();//Counts the number of characters to delete ele.click(); //Tapping or Clicking on the textfield // Deleting or Clearing the textfield off of the prefilled values for(int i=0;i<characters_to_delete;i++){ driver.findElement(By.xpath("//Locator of the Keyboard button 'Delete' ")).click(); } ele.sendKeys("value to be filled in the textfield"); //Filling the textfield with the value
We can use selectAll if tests are executing on android.
It will select entire text and will press delete.
I was able to resolve this issue using the code below as "textField().clear()" didn't appear to work on some devices and emulators such as Genymotion.
while (!textField().getText().isEmpty()) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(textField());
driver.getKeyboard().sendKeys(Keys.DELETE);
}
The code would loop through until textfield is cleared. Hope this helps, works for both Android and iOS.
This thing can be overcome by using the latest version of appium. In older version clear sometimes doesn't clear all the text-fields in case of longer text.
A click on to the textBox before you clear should do with the latest libs:
WebElement mob = driver.findElement(By.name("Mobile Number"));
mob.click();
mob.clear();
OR from the sample jUnitTest here
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
text.sendKeys("12");
text.clear();
I guess