Tuesday, March 25, 2025

selenium webdriver – CLEAR Technique skipped whereas operating the checks


You need to 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 `dwelling` keypresses.
        multipleKeyStrokes(locator, "finish");
        multipleKeyStrokes(locator, "shift+dwelling");
        multipleKeyStrokes(locator, "backspace");
    }
    return true;
}

personal boolean toBeCleared(Object factor) {
    boolean flag = true;

    String jText = (String) _js.executeScript("return $(arguments[0]).val();", factor);
    String textual content = _query.getText(factor);

    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 need to use Actions class to simulate keypresses, I’ve used javascript to take action within the multipleKeyStrokes() technique.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles