Selenium webdriver explicit wait

后端 未结 7 1452
无人共我
无人共我 2021-01-03 10:21

I\'m writing some automated tests for using the selenium chrome driver. I trying to write a reusable method that will explicitly wait for elements to appear and then call th

7条回答
  •  孤街浪徒
    2021-01-03 11:05

    I wrote an explicit wait for my selenium test in the following manner:

    I declared my WebElement to be found with an @FindBy annotation added referencing the Id as follows:

    @FindBy(how = How.ID, using = "home")
    private WebElement home;
    

    Then my method that waits for an element to load was written as follows:

    public WebElement isElementLoaded(WebElement elementToBeLoaded) {
        WebDriverWait wait = new WebDriverWait(driver, 15);
        WebElement element = wait.until(ExpectedConditions.visibilityOf(elementToBeLoaded));
        return element;
    }
    

    This allowed me to reference any element I was waiting for by name that I had annotated with a find by, regardless of the @FindBy method used.

提交回复
热议问题