要将webdriver的执行挂起毫秒,可以按如下方式传递number of seconds或{}:import time
time.sleep(1) #sleep for 1 sec
time.sleep(0.25) #sleep for 250 milliseconds
然而,当使用硒和WebDriver来实现自动化时,使用time.sleep(secs)而没有任何特定的条件来实现自动化的目的,因此应不惜任何代价加以避免。根据文件: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.
因此,根据讨论,您应该使用^{}和{a2}一起使用,而不是{cd4>}来验证元素的状态,三个广泛使用的预期条件如下:
已定位元素的存在
元素的可见性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.
元素可点击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.
参考文献