Wait for page load in Selenium

后端 未结 30 2474
攒了一身酷
攒了一身酷 2020-11-22 07:12

How do you make Selenium 2.0 wait for the page to load?

30条回答
  •  孤街浪徒
    2020-11-22 08:16

    NodeJS Solution:

    In Nodejs you can get it via promises...

    If you write this code, you can be sure that the page is fully loaded when you get to the then...

    driver.get('www.sidanmor.com').then(()=> {
        // here the page is fully loaded!!!
        // do your stuff...
    }).catch(console.log.bind(console));
    

    If you write this code, you will navigate, and selenium will wait 3 seconds...

    driver.get('www.sidanmor.com');
    driver.sleep(3000);
    // you can't be sure that the page is fully loaded!!!
    // do your stuff... hope it will be OK...
    

    From Selenium documentation:

    this.get( url ) → Thenable

    Schedules a command to navigate to the given URL.

    Returns a promise that will be resolved when the document has finished loading.

    Selenium Documentation (Nodejs)

提交回复
热议问题