I have been writing selenium scripts for a while in Java. I encountered a very weird issue today. Here is the issue:
I cleared a text field using webelement.clear() method, later while executing next command (click event), the text area I had previously cleared, is now populated with previously filled value.
Here is the code snippet:
mobileNumField.get(0).clear();
Thread.sleep(4500);
emailAddress.get(0).click();
emailAddress.get(0).clear();
Thread.sleep(4500);
emailAddress.get(0).sendKeys(Keys.TAB);
clear( ) predefined method of Selenium 'WebDriver' Class is used to clear the text entered or displayed in the text fields. Now lets clear the text inside the Text Area field using the clear( ) predefined method of Selenium 'WebDriver' class.
Navigate to the Chrome settings page with Selenium by executing the driver. get('chrome://settings/clearBrowserData') . Click on the Clear Data button to clear the cache.
As shown clearly in the script for this example, you simply need to use element. clear() where element is the text input.
The findElements command returns an empty list if there are no elements found using the given locator strategy and locator value. Below is the syntax of findElements command.
I don't know the exact reason for your element keeping its value, but you can try an alternative text clearance by sending 'Ctrl+A+Delete' key combination using sendKeys method of the element's object:
emailAddress.sendKeys(Keys.chord(Keys.CONTROL,"a", Keys.DELETE));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With