小编Bil*_*ill的帖子

如何在Wait.until()中使用selenium 2 PageFactory init元素?

下面的代码片段工作正常,但我在使用该wait.until()行时有点麻烦:

wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
Run Code Online (Sandbox Code Playgroud)

它有效,但我想发送我的PageFactory WebElement homePageLink代替:

wait.until(new ElementPresent(homePageLink));
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

这些新奇的Selenium 2功能让我的头脑有点旋转,我找不到太多的文档.

谢谢.

public class GoogleResultsPage extends TestBase {

    @FindBy(xpath = "//a[@title='Go to Google Home']")
    @CacheLookup
    private WebElement homePageLink;

    public GoogleResultsPage() {  
        wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
        assertThat(driver.getTitle(), containsString("Google Search"));
    }  
}

public class ElementPresent implements ExpectedCondition<WebElement> {

    private final By locator;

    public ElementPresent(By locator) {
        this.locator = locator;
    }

    public WebElement apply(WebDriver driver) {
        return driver.findElement(locator);
    }
}
Run Code Online (Sandbox Code Playgroud)

selenium webdriver

14
推荐指数
1
解决办法
2万
查看次数

标签 统计

selenium ×1

webdriver ×1