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;
@Before
public void setUp() throws Exception {
driver = new SafariDriver();
}
@After
public void tearDown() throws Exception {
driver.close();
}
@Test
public void testGoogleSearch() {
driver.get("http://duckduckgo.com");
driver.findElement(By.id("search_form_input_homepage")).sendKeys("Hello World");
driver.findElement(By.id("search_button_homepage")).click();
driver.findElement(By.linkText("Images")).click();
}
}
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?