Selenium webdriver explicit wait

后端 未结 7 1451
无人共我
无人共我 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 10:43

    I built a package using Selenium and waiting was one of the biggest issues I had. In the end, the methods as you described above wouldn't work. I had to resort to doing a simple implicit wait for any dynamic elements, as described below

    An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

    Code:

    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://somedomain/url_that_delays_loading");
    WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
    

    src

    Hope that helps.

提交回复
热议问题