I am using the time library in my script:

import time

time.sleep(1)

It can sleep my webdriver for 1 second but I need to sleep it for 250 milliseconds.

解决方案

To suspend the execution of the webdriver for milliseconds you can pass number of seconds or floating point number of seconds as follows:

import time

time.sleep(1) #sleep for 1 sec

time.sleep(0.25) #sleep for 250 milliseconds

However while using Selenium and WebDriver for Automation using time.sleep(secs) without any specific condition to achieve defeats the purpose of Automation and should be avoided at any cost. As per the documentation:

time.sleep(secs) suspends the execution of the current thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

So as per the discussion instead of time.sleep(sec) you should use WebDriverWait() in-conjunction with expected_conditions() to validate an element's state and the three widely used expected_conditions are as follows:

presence_of_element_located

class selenium.webdriver.support.expected_conditions.presence_of_element_located(locator)

Parameter : locator - used to find the element returns the WebElement once it is located

Description : An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible or interactable (i.e. clickable).

visibility_of_element_located

class selenium.webdriver.support.expected_conditions.visibility_of_element_located(locator)

Parameter : locator - used to find the element returns the WebElement once it is located and visible

Description : An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

element_to_be_clickable

class selenium.webdriver.support.expected_conditions.element_to_be_clickable(locator)

Parameter : locator - used to find the element returns the WebElement once it is visible, enabled and interactable (i.e. clickable).

Description : An Expectation for checking an element is visible, enabled and interactable such that you can click it.

Reference

You can find a detailed discussion in WebDriverWait not working as expected

python sleep 毫秒_如何在python中休眠Webdriver毫秒相关推荐

  1. python 线性回归模型_如何在Python中建立和训练线性和逻辑回归ML模型

    python 线性回归模型 Linear regression and logistic regression are two of the most popular machine learning ...

  2. unbantu上python安装步骤_如何在Ubuntu中安装Python 3.6?

    Python是增长最快的主要通用编程语言.原因有很多,比如它的可读性和灵活性,易于学习和使用,可靠和高效. 有两个主要的Python版本被使用- 2和3 (Python的现在和未来);前者将看不到新的 ...

  3. python进程暂停_如何在Python中暂停多进程?

    我希望用户能够在怎么开始的实现它?在 我的代码是:# -*- coding: utf-8 -*- from PySide import QtCore, QtGui from Ui_MainWindow ...

  4. python 拟合正态分布_如何在Python中拟合双高斯分布?

    我试图使用Python获得数据(link)的双高斯分布.原始数据的格式为: 对于给定的数据,我想获得图中所示峰值的两个高斯分布.我用以下代码(source)进行了尝试:from sklearn imp ...

  5. python 概率分布函数_如何在Python中实现这五类强大的概率分布

    匿名用户 1级 2016-04-25 回答 首页 所有文章 观点与动态 基础知识 系列教程 实践项目 工具与框架应用 工具资源 伯乐在线 > Python - 伯乐在线 > 所有文章 &g ...

  6. python mqtt库_如何在 Python 中使用 MQTT

    Python 是一种广泛使用的解释型.高级编程.通用型编程语言.Python 的设计哲学强调代码的可读性和简洁的语法(尤其是使用空格缩进划分代码块,而非使用大括号或者关键词).Python 让开发者能 ...

  7. python 获取当前目录_如何在Python中获取当前的工作目录?

    python 获取当前目录 To get the current working directory in Python, there is a library function getcwd() i ...

  8. eclipse配置python开发环境_如何在Eclipse中配置python开发环境

    展开全部 步骤1: 下载用于在2113Eclipse中开发Python的插件PyDev. 步骤2: 解压5261python.将解压后的features和plugins文件4102夹中的1653内容拷 ...

  9. win10系统64位安装python什么版本_如何在win10中安装Python

    本文主要讲解win10如何安装python,希望对初学的小伙伴有帮助.环境:win 10 64位操作系统1.python下载https://www.python.org/downloads/2.x和3 ...

  10. python标题行_如何在python datafram中更改标题行

    在python中使用pandas更改现有数据帧中的头行时遇到问题.导入pandas和csv文件后,我将一个标题行设置为None,以便能够在转置后删除重复的日期.但是这会留下一个我不想要的行标题(实际上 ...

最新文章

  1. 发布文件打包springboit_程序安装包咋制作的?Qt程序打包三部曲,从应用程序到安装包...
  2. AJAX与WebService
  3. ​GPLinker:基于GlobalPointer的实体关系联合抽取
  4. 神经机器阅读理解最新综述:方法和趋势
  5. python中raw函数_Python apply函数
  6. mysql编写函数 求1 n 偶数之和,编写求1 2 3 - n的函数.在main函数中调用该函数
  7. [Ext JS6] ViewControllers-视图控制器
  8. JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)
  9. Flash Builder 4 正式版序列号
  10. 上位机、下位机、单片机的关系
  11. 2006年100款最佳安全工具谱
  12. springboot学习笔记1——springboot初始化
  13. 手机重装为linux,安卓手机重装系统的方法
  14. Idea 报错: Variable used in lambda expression should be final or effectively final
  15. 43.248.189.18 Steam游戏服务器搭建教程
  16. html文本框后面紧挨着按钮,Word题目与答案
  17. N皇后问题---线性方程处理
  18. 恢复系统映像时错误代码0X80070057的解决方案
  19. 《C语言入门100例》(第5例) 绝对值
  20. 量化交易是如何赚钱的?

热门文章

  1. Eclipse中设置自定义文档签名
  2. spark提交任务的两种的方法
  3. .net读取Lotus Domino文件数据库
  4. C语言中strstr函数
  5. Servlet接收JSP参数乱码问题解决办法
  6. python爬取商品信息
  7. angular : direative :comunication 指令之间的通讯
  8. PHP cookie和session的分析
  9. [小知识] 关于Excel中行列的固定
  10. python中 os._exit() 和 sys.exit(), exit(0)的用法和区别