Appium : Clear a field

后端 未结 26 3214
野趣味
野趣味 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:43

    This normally happens when the opened screen in your app, is a "WebView".

    When faced with similar problem, I followed the below steps:

    1. Got the value of the textfield, i.e., prefilled text, using the "getAttribute" method. And, then retrieved the length of the string, so as to know how many characters are present to delete

    2. Tapped on the textfield.

    3. Deleted the characters inside the textfield using the "Delete button" element of the iOS Keyboard.

    4. Filled the necessary value in the textfield.

    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
        

提交回复
热议问题