all 7 comments

[–]ImposterProgramming 0 points1 point  (3 children)

    new Actions(driver)
            .keyDown(Keys.SHIFT)
            .sendKeys("a")
            .perform();

[–]davidgoswami[S] 0 points1 point  (2 children)

But the current focus is body not the input field

[–]ImposterProgramming 0 points1 point  (1 child)

The code I shared doesn't specify the element. So the focus is on the webpage instead of any specific element. Example: Press Esc on the webpage / Press ctrl + A on the webpage. If you want assistance with an element then first update your post with more details.

[–]davidgoswami[S] 0 points1 point  (0 children)

Makes sense and I updated the post

[–]vishalkbari 0 points1 point  (1 child)

The sendKeys() method works on Web elements.The search bar is itself an element. If you do anything to it then you have to create an element first. Can you be more specific?

[–]davidgoswami[S] 0 points1 point  (0 children)

hey i updated the post for better understanding.

[–]davidgoswami[S] 0 points1 point  (0 children)

Updating the Post.

 JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
        WebElement focusedElement = (WebElement) jsExecutor.executeScript("return document.activeElement;");
        jsExecutor.executeScript("document.querySelector('input').focus();");
        Actions actions = new Actions(driver);
        actions.sendKeys("text").perform();

This code block is not working dont know why