selenium ---- three kinds wait

In doing UI test automation, often we encounter poor network environment, leading to the elements and can not find an error, then we should use in waiting selenium. There are three in selenium in standby mode

time (fixed latency)
using the format: time.sleep (seconds)
in this way, although you can customize the wait time, but in the network environment is good, it still will continue to wait according to the set time, resulting in prolonged automation, not recommended.

implicitly_wait (hermit wait)
using the format: driver.implicitly_wait (seconds The)
hermit wait actually set a maximum waiting time, if the page load completed within the stipulated time, then the next step, otherwise wait until the end of time, then the next step.
Hermit waiting, has faults, we all know js generally last load in the body, in fact, then the page has finished loading, are still waiting for the entire page has finished loading. Hermits are waiting for the entire work cycle driver,

just at the very beginning set once on the line, do not wait to use as fixed, at each step plus hermit wait.

WebDriverWait (wait display)
1, first package import WebDriverWait

from selenium.webdriver.support.wait import WebDriverWait

2, WebDriverWait parameters
using the format: WebDriverWait (driver, timeout, poll_frequency )

WebDriverWait(driver,10,0.5)

driver: Incoming WebDriver instance, that our driver on the case
: timeout timeout, maximum time
poll_frequency: call interval of time until until_not methods or default is 0.5 seconds
ignored_exceptions: ignore the exception if the call process until an exception is thrown or until_not in this tuple, not interrupt code, continue to wait, if an exception is thrown out of this tuple,
the interrupt code, an exception is thrown. By default only NoSuchElementException.

This module There are two ways: until and not an until
an until: When an element is present or what condition is satisfied then continue
until not: when an element disappear or what conditions does not hold continue with
these two methods need to introduce a module of selenium

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

 

 



Guess you like

Origin www.cnblogs.com/yttbk/p/11024610.html