wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)

后端 未结 8 1142
遇见更好的自我
遇见更好的自我 2020-12-14 12:30

I want use wait.until(ExpectedConditions) with TWO elements. I am running a test, and I need WebDriver to wait until either of Element1 OR

8条回答
  •  旧时难觅i
    2020-12-14 12:51

    If you have a variable number of conditions to satisfy, you can leverage a generic list such as Java's ArrayList<> as shown here, and then do the following:

    //My example is waiting for any one of a list of URLs (code is java)
    
        public void waitUntilUrls(List urls) {
            if(null != urls && urls.size() > 0) {
                System.out.println("Waiting at " + _driver.getCurrentUrl() + " for " + urls.size() + " urls");
                List> conditions = new ArrayList<>();
                for (String url : urls) {
                    conditions.add(ExpectedConditions.urlContains(url));
                }
    
                WebDriverWait wait = new WebDriverWait(_driver, 30);
                ExpectedCondition[] x = new ExpectedCondition[conditions.size()];
                x = conditions.toArray(x);
                wait.until(ExpectedConditions.or(x)); // "OR" selects from among your ExpectedCondition array
            }
        }
    

提交回复
热议问题