Wait for an element using Selenium webdriver

后端 未结 4 658
耶瑟儿~
耶瑟儿~ 2021-01-23 07:11

What is the best way to wait for an element to appear on a web page? I have read that we can use implicit wait and functions like webdriverwait, fluentwait etc and last but not

4条回答
  •  失恋的感觉
    2021-01-23 07:51

    public boolean waitForElement(WebElement ele, String xpath, int seconds) throws InterruptedException{
        //returns true if the xpath appears in the webElement within the time
        //false when timed out
        int t=0;
        while(t0)
                return true;
            else{
                Thread.sleep(100);
                t++;
                continue;
            }
        }       
        System.out.println("waited for "+seconds+"seconds. But couldn't find "+xpath+ " in the element specified");
        return false;
    }
    

提交回复
热议问题