使用AjaxElementLocatorFactory和显式等待之间有什么区别

时间:2020-07-02 10:41:44

标签: java selenium selenium-webdriver

我试图了解Explicit(fluent)等待与使用AjaxElementLocatorFactory等待之间的区别

我已经看到使用Page Factory的Page Object Model框架 PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this); 根据我的理解,这将等待默认的15秒,以便使用@FindBy定义的元素可见。这是正确的理解吗?

与此同时,我也看到了使用显式等待的Page类。

public @FindBy(xpath = "//a[@class=\"flex-next\"]") WebElement next;
    public HomePage clickNext() throws InterruptedException, IOException {
        waitAndClickElement(next);
        return new HomePage();
    }

    public void waitAndClickElement(WebElement element) throws InterruptedException {
        boolean clicked = false;
        int attempts = 0;
        while (!clicked && attempts < 10) {
            try {
                this.wait.until(ExpectedConditions.elementToBeClickable(element)).click();
                System.out.println("Successfully clicked on the WebElement: " + "<" + element.toString() + ">");
                clicked = true;
            } catch (Exception e) {
                System.out.println("Unable to wait and click on WebElement, Exception: " + e.getMessage());
                Assert.fail("Unable to wait and click on the WebElement, using locator: " + "<" + element.toString() + ">");
            }
            attempts++;
        }
    }

这是正确的使用方式吗? 我们在复制东西吗?

0 个答案:

没有答案