Appium : Clear a field

后端 未结 26 2945
野趣味
野趣味 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 17:04
    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.

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

    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.

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

    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.

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

    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.

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

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