2
votes

clear method clears the value but retains and when send keys new value is passed the text box shows previous value + new value in selenium Appium. Kindly suggest. Version:java-client-4.1.2 Appium Server:v1.7.2 Selenium: 3.0.1

I tried this but it did not work out.

public void clearTextBox(WebElement element,String text) throws Exception
  {
     element.click();
     Thread.sleep(3000);
     element.clear();
     element.sendKeys(text);
  }

Getting this enter image description here

enter image description here

1
You should use first driver.findElement(editFieldId).clear(); then driver.findElement(editFieldId).sendKeys("ABC");Al Imran
I am using the below mentioned code but it is not working. It appends the previous number + new number which is sent in sendKeys() Appium_Mobile_Page.Msisdn.click(); Appium_Mobile_Page.Msisdn.clear(); Thread.sleep(3000); Appium_Mobile_Page.Msisdn.sendKeys(msisdn);Abhishek Gaur

1 Answers

0
votes

The reason your code is failing (and you should have included your code in the original question) is because you are doing it through TWO separate calls to the page object element.

Each time you call the page object, it looks-up the element freshly, so the first time you call it and issue a .clear() and then you are calling it again after an unnecesary sleep with the .sendkeys() method. The click is also unnecessary.

You should write a public method in your page object model to perform the sendkeys() for you which does the clear() and then the sendkeys(), i.e.:

public void setMsisdnValue(String text) {
    Msisdn.clear();
    Msisdn.sendKeys(text);
}

Personally, I use a set of helper methods so that I can error-trap and log things like sendkeys, but I would still call it from within the page object model itself. That helper would do the same two steps, but also do it inside a try/catch and report any errors, so it would be simplified to:

public void setMsisdnValue(String text) {
    helper.sendKeys(Msisdn, text);
}

Hope this helps.