You should use the next technique to clear textual content fields, it’s examined on several types of enter fields
public boolean clearTextField(Object locator) {
_element = _query.castLocator(locator);
if (toBeCleared(_element)) {
_element.clear();
}
if (toBeCleared(_element)) {
_mouse.click on(locator);
// simulate choose all textual content utilizing `finish`, `shift` and `house` keypresses.
multipleKeyStrokes(locator, "finish");
multipleKeyStrokes(locator, "shift+house");
multipleKeyStrokes(locator, "backspace");
}
return true;
}
personal boolean toBeCleared(Object component) {
boolean flag = true;
String jText = (String) _js.executeScript("return $(arguments[0]).val();", component);
String textual content = _query.getText(component);
if (_verify.isStringMatch("", jText) && _verify.isStringMatch("", textual content)) {
flag = false;
}
return flag;
}
public boolean multipleKeyStrokes(Object locator, String keys) {
_element = _query.castLocator(locator);
_browser.checkAndInjectSimulations();
_js.executeScript("$(arguments[0]).simulate('key-combo', {combo: arguments[1]})", _element, keys);
return true;
}
You should use Actions
class to simulate keypresses, I’ve used javascript to take action within the multipleKeyStrokes()
technique.