I'm automating the input to a search bar; the program work fine when using chrome driver, but fails when I try to use PhantomJS.

The text that should go in the search bar is not being typed properly:

WebElement searchBar =  driver.findElement(By.cssSelector("input.sbox-ui-input"));

util.waitFor(3); // we wait to get all the possible suggestions

I also tried this code:

Actions action = new Actions(driver);
action.sendKeys(searchBar, query).build().perform();

None of them are working. Is there another way to 'type' the text in the input/search bar?

I often had a similar problem when clicking certain buttons, so I had a script like this that worked with PhantomJS:

WebElement commentsRecent = driver.findElements(By.cssSelector("button.someButtonClass")).get(1);
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", commentsRecent);

Is there something similar for sending text input?

  • Looks like you found a solution to your problem based on your comment on the answer. You might consider adding what worked for you as an answer and accepting it so that it's clear this question was resolved.
    – c32hedge
    May 24, 2017 at 16:50

1 Answer 1


You can try to wait for the searchBar than try to get the cursor(Focus) to desired WebElement using .clear() and then try to send keys.

// Initialise instance of WebDriverWait class with 30 seconds of wait time.
WebDriverWait wait = new WebDriverWait(driver , 30)

WebElement searchBar =  driver.findElement(By.cssSelector("input.sbox-ui-input"));
searchBar.clear(); //Get the cursor(Focus) to the searchBar
  • 1
    that helped a bit, but after hours of reading documentation on internet and forums this code worked: .contextClick().build().perform().
    – Progs
    Jan 24, 2017 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.