Make Selenium wait 10 seconds

后端 未结 1 1064
甜味超标
甜味超标 2020-12-25 11:18

Yes I know the question has been asked quite often but I still don\'t get it. I want to make Selenium wait, no matter what. I tried these methods

driver.set         


        
1条回答
  •  情歌与酒
    2020-12-25 11:51

    All the APIs you have mentioned is basically a timeout, so it's gonna wait until either some event happens or maximum time reached.

    set_page_load_timeout - Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.

    implicitly_wait - Specifies the amount of time the driver should wait when searching for an element if it is not immediately present.

    set_script_timeout - Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.

    for more information please visit following page. (documention is for JAVA binding, but functionality should be same for all the bindings) https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#implicitlyWait-long-java.util.concurrent.TimeUnit-

    So, if you want to wait selenium (or any script) 10 seconds, or whatever time. Then the best thing is to put that thread to sleep.

    In python it would be

    import time 
    time.sleep(10)
    

    In JAVA it would be

    The simple way to do this is using

        try {
            Thread.sleep(10*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    

    0 讨论(0)
提交回复
热议问题