pyhon学习之selenium模拟等待,直到....才,等待加载。

driver.implicitly_wait(30)
driver.find_element_by_id("su").click()

    # Timeouts
    def implicitly_wait(self, time_to_wait):
        """
        Sets a sticky timeout to implicitly wait for an element to be found,
           or a command to complete. This method only needs to be called one
           time per session. To set the timeout for calls to
           execute_async_script, see set_script_timeout.

        :Args:
         - time_to_wait: Amount of time to wait (in seconds)

        :Usage:
            driver.implicitly_wait(30)
设置查找元素的异步等待时长。
或者是一个即将完成的命令。
这个方法在一个session中只能调用一次,一个session就是一个会话,直到关闭浏览器窗口(session生存周期)
设置一步执行调用js,可以查看set_script_timeout.


        """
        if self.w3c:
            self.execute(Command.SET_TIMEOUTS, {
                'implicit': int(float(time_to_wait) * 1000)})
        else:
            self.execute(Command.IMPLICIT_WAIT, {
                'ms': float(time_to_wait) * 1000})

我们可以在一些网页中加载某一些网址的时候进行设置。就不需要通过sleep固定等待了。同时也推荐这种用法。

猜你喜欢

转载自blog.csdn.net/rubikchen/article/details/84591818