Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Selenim learning: setting element wait

Shulou Source: shulou.com Published: 2022-06-03 04:40:58 11月25日 Update

Show wait

Show wait for Webdriver to continue execution when a condition is established, otherwise a timeout exception is thrown when the maximum length of time is reached (TimeoutException)

From selenium import webdriverfrom time import * from selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EC# renamed expected_conditions to ECdriver = webdriver.Chrome () url = 'http://www.baidu.com'driver.get(url)element = WebDriverWait (driver,5,0.5). Until (EC.presence_of_element_located ((By.ID,'kw')) element.send_keys (' selenium') sleep (5) driver.quit ()

The WebDriverWait class is a wait method provided by WebDriver. Within the set time, by default, whether the current page element exists is detected by default, and an exception is thrown if it cannot be detected beyond the setting time.

2.sleep method

The sleep () method is provided by the time module of python

Tags: Method time detection element maximum duration is made up of condition module page learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Linux vpn macOS