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:
driver.findElement(By.name("Mobile Number")).clear();
this works for me. I am using find element by id and then calling clear.
wd.findElement(By.id("username")).clear();
This clears the pre-entered data in the field user name in my case.
It's about login screen so i would suggest to restart the app each time you run your script, go to appium and check Full Reset in Android Settings.
What helped for me was to add an empty sendKeys before the clear.
Like this:
public void sendKeysToElement(WebElement element, String keys) {
element.sendKeys("");
element.clear();
element.sendKeys(keys);
driver.hideKeyboard();
}
This method is used for all our input fields. Without the empty sendKeys it was not clearing all the fields properly.
I have faced the same issue, but i found one proper solution.
public void clearTextBox(WebElement element) throws Exception
{
element.click();
element.sendKeys(Keys.CONTROL + "a");
element.sendKeys(Keys.DELETE);
}
It will work for sure.
def Clear(self):
self.driver.keyevent(123)#Move Cursor Last one
time.sleep(2)
for i in range(10):
self.driver.keyevent(67)#Deleted Keyboard
self.driver.implicitly_wait(60)
I HAD A HARD TIME IN SOLVING THIS ISSUE AS WHILE AUTOMATING ios APP was unable to clear a specific field
was not able to use any other alternatives as well so this worked out in my case!
1.Get the XPath of delete button of keyboard and then loop it and use click method to clear it this is what worked in my case
for(int x=1;x<6;x++)
{
driver.findElementByXpath("//XCUIElementTypeKey[@name='Delete']").click;
}