Appium : Clear a field

后端 未结 26 2944
野趣味
野趣味 2020-12-16 16:03

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:

相关标签:
26条回答
  • 2020-12-16 16:55

    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.

    0 讨论(0)
  • 2020-12-16 16:55

    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("");
    
    0 讨论(0)
  • 2020-12-16 16:57

    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
    
    0 讨论(0)
  • 2020-12-16 16:58

    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);
    
    }
    
    0 讨论(0)
  • 2020-12-16 16:59

    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.

    0 讨论(0)
  • 2020-12-16 17:03

    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++;
        }
    
    0 讨论(0)
提交回复
热议问题