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:
you might want to refrain from using appium's built in clear method.
you can try using adb shell input keyevent 67 which sends a delete keyevent to android. this works on all versions pretty much.
you can just click the textfield twice to highlight the text:
WebElement mob = driver.findElement(By.tagName("editText"));
that would locate the first textField avilable, as other methods in selenium bindings, you can try findElements as well, and get all the textfields in an array, and you can choose whichever you meant to manipulate.
then, send an input keyevent 67 to delete the whole field.
I am using a double tab and send an empty key to the field. This works stable in my UI tests.
new TouchAction<>((AndroidDriver<?>) driver).tap(new TapOptions().withTapsCount(2).withElement(new ElementOption().withElement(element))).perform();
element.sendKeys("");
I use cucumber
and ruby
to write my tests and this one works good for both iOS and Android for me.
arg1
and arg2
are the input values that I give in the gherkin
steps.
And(/^I enter "([^"]*)" on identifier "([^"]*)"$/) do |arg1, arg2|
Input = find_element(id: arg2)
Input.click
Input.clear
Input.send_keys(arg1)
end
This method worked for me, although I am trying for a better solution. In the meantime please use this method.
public void clear(String locatorType, String locator, long... waitSeconds)
{
WebElement we = getElementWhenPresent(getByLocator(locatorType, locator), waitSeconds);
String text = we.getText();
int maxChars = text.length();
//we.clear() is not working
for (int i = 0; i < maxChars; i++)
((AppiumDriver)driver).sendKeyEvent(67);
}
If the text field contains any pre-specified mobile number, please do in the following way.
WebElement mob = driver.findElement(By.name("xxxxxxxxxx")); mob.clear();
xxxxxxxxxx: mobile number that is pre-specified while opening the application.
Else use some other locating techniques like By.xpath , By.id(if you are testing android and Selendroid as capability) etc.
For iOS, I can perform backspace/delete by using below code of snippet:
//Get the keyword
String name = driver.findElement(by).getText();
WebElement e1 = driver.findElement(by);
System.out.println("Length of Keyword = " +name.length());
int count = 0;
int keywordlength = name.length();
//click on keyword textbox
e1.click();
while (count < keywordlength) {
//Clear the keyword
TouchAction ta = new TouchAction(driver);
ta.longPress(e1);
driver.getKeyboard().sendKeys(Keys.DELETE);
count++;
}