-1

我们可以有一个通用的等待方法...即(1.等待页面加载 2.查找元素 3.如果未找到刷新),这种情况一直持续到 fluentwait 超时。

4

2 回答 2

1

您可以将WebdriverWait用于所有 - (1.等待页面加载 2.查找元素 3.如果未找到刷新)

   WebDriverWait wait = new WebDriverWait(driver, 18); // Times Out after 18 Seconds
    PageUtil.refreshObject(driver, By.linkText("Element")); // refresh the Element
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Element"))); // wait till  Element is Enabled and Visible before Clicking on that Element

    /**
    *Pass the Control to that Element and Click on that Element (preferred in IE)
    *
    */
    WebElement element = driver.findElement(By.linkText("Element"));
    element.sendKeys(org.openqa.selenium.Keys.CONTROL);
    element.click();

这是RefreshObject方法,PageUtil是 ClassName

public static WebElement refreshObject(WebDriver driver, By locator) {
        int counter = 0;

        try {
            counter = counter + 1;

            return driver.findElement(locator);
        }

        catch (StaleElementReferenceException e) {

            return refreshObject(driver, locator);

        }

    }
于 2013-11-12T07:30:33.277 回答
0

您是否有特殊的商业案例需要这样做?如果你不这样做,你可以在设置驱动程序对象时设置一个隐式等待。在 c# 中,它看起来像:

myDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

许多人会说你应该避免隐式等待,但如果你觉得你需要去构建一个方便的方法,那么隐式等待可能更可取。

于 2013-10-23T19:33:22.623 回答