首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium SafariDriver不等待页面加载吗?

Selenium SafariDriver不等待页面加载吗?
EN

Stack Exchange QA用户
提问于 2017-08-02 21:56:58
回答 1查看 1.7K关注 0票数 1

看来Selenium的SafariDriver不需要等待网页的加载。我的测试如下:

代码语言:javascript
复制
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();
    }
}

如果您使用ChromeDriver (或FirefoxDriver )运行此操作,它将按应有的方式运行,即搜索"Hello“,然后在结果页面上转到图像结果。

对于SafariDriver,它在以下方面失败:

代码语言:javascript
复制
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)

无法找到的元素是“图片”,因为页面在运行该语句之前还没有加载。

,这是预期的行为吗?我应该为Safari做特例吗?

EN

回答 1

Stack Exchange QA用户

发布于 2017-08-02 21:59:35

您必须在WebDriverWait中使用一个显式等待来说明这一点:

代码语言:javascript
复制
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);

WebElement images = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Images")));
images.click();
票数 1
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/28889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档