-1

The following code isused to clear the text box value or we can use this to clear the text box in selenium if the clear() function is not working use below code `

 if (maturityDate.compareTo(currentDate)<0) { System.out.println("Maturity Date is less than today date"); renewalMaturityDate.click(); JavascriptExecutor js = (JavascriptExecutor)selenium; js.executeScript("arguments[0].value = '';", renewalMaturityDate); renewalMaturityDate.sendKeys(futuredate); } else if (maturityDate.compareTo(currentDate)>0) { System.out.println("Maturity Date is Greater than today date"); renewalMaturityDate.click(); JavascriptExecutor js = (JavascriptExecutor)selenium; js.executeScript("arguments[0].value = '';", renewalMaturityDate); renewalMaturityDate.sendKeys(maturityDate); rm.waitForSeconds(1); } 
1

1 Answer 1

0

It isn't necessary to use JS Executor to clean InputField.

One of the solutions is using org.openqa.selenium.Keys:

element.sendKeys(Keys.chord(Keys.CONTROL, "a", Keys.DELETE)); 
1
  • recently i am not able to clear text box value using node js web application so i found that JS Executor to clean Input FieldCommentedFeb 6, 2024 at 12:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.