Sometimes you need to add a wait time to your script in order to keep the pace running stable.
- Add hibernation: The time package needs to be introduced, and a fixed wait is selected. Example: Import time .... time.sleep (2)
- Smart wait: By adding implicitly_wait (), you can intelligently wait within a time frame. Implicitly waits for an element to be discovered or a command to complete: This method needs to be called only once per session. Example: Browser.implicitly_wait (30),
- The Webdriverwait class is provided in Webdriver, which can intelligently wait for the page element to be loaded and then perform the operation. Instance:
Wait=webdriverwait (Webdriver.chrome (), 30)
Ele=wait.until (Lambda X:x.find_element_by_xpath (XPath))
Ele.click ()
Determine whether an element exists or not:
def isPresent (self):
Try
Driver.find_element_by_xpath (XPath)
EXCEP nosuchelementexception,e:
Return False
Else
Return True
Selenium Python Learning Notes---Add wait time