It appears that the SafariDriver for Selenium doesn't wait for web pages to load. My test is as follows:

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.safari.SafariDriver;

public class SafariTest {

    private WebDriver driver;

    public void setUp() throws Exception {
        driver = new SafariDriver();

    public void tearDown() throws Exception {

    public void testGoogleSearch() {
        driver.findElement(By.id("search_form_input_homepage")).sendKeys("Hello World");

If you run this with ChromeDriver, or FirefoxDriver, it functions as it should, i.e. it searches for "Hello World", then on the results page, it goes to the image results.

With SafariDriver, it fails with:

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)

The element that could not be found being "Images", since the page hasn't loaded before it ran that statement.

Is this expected behavior? Am I supposed to special case for Safari?


You have to account for that with an Explicit Wait with WebDriverWait:

WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);

WebElement images = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Images")));
  • 1
    Why would I have to do this only with Safari and no other browser? – Roxy Aug 3 '17 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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