python sleep 毫秒_如何在python中休眠Webdriver几毫秒

要暂停执行 webdriver毫秒,您可以通过number of seconds或执行floating point number of seconds以下操作:

import time

time.sleep(1) #sleep for 1 sec

time.sleep(0.25) #sleep for 250 milliseconds

但是,在将Selenium和WebDriver用于自动化时,在time.sleep(secs)没有任何特定条件的情况下使用将达到 自动化的目的,因此应不惜一切代价避免使用。根据文档:

time.sleep(secs)在给定的秒数内暂停当前线程的执行。该参数可以是浮点数,以指示更精确的睡眠时间。实际的暂停时间可能少于请求的暂停时间,因为任何捕获到的信号都会在执行该信号的捕获例程后终止sleep()。而且,由于系统中其他活动的调度,暂停时间可能比请求的时间长任意数量。

因此,按照讨论,而不是time.sleep(sec)您应该使用WebDriverWait()in-conjunction与expected_conditions()来验证元素的状态,并且三个广泛使用的Expected_conditions如下:

present_of_element_located

present_of_element_located(locator)的定义如下:

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).

visible_of_element_located

visible_of_element_located(locator)定义如下:

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

element_to_be_clickable(locator)定义如下:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值