Unable to send character by character in search box with sendKeys

I need to replicate human behaviour with search box where it recommends search suggestion.
The problem is whenever i’m sending character by character of the string into search box, the previous state of text in search box gets cleared and only the current character in the loop is entered into search box.

Please help!

public void sendHumanKeys(WebElement element, String str){
        element.click();
        if (str!= null && !element.getText().isEmpty()){
            element.clear();
        }
        for (int i= 0; i< str.length(); i++){
            element.click();
            element.sendKeys(str.charAt(i));
        }
    }

@bipin open keyboard with Tap into input. then try:

driver.getKeyboard().pressKey("My Text");
1 Like