Seleniumselenium等待元素出现

WebDriverWait,配合该类的until()和until_not()方法,表示程序每隔x秒去判断一下指定的元素是否加载完,加载完了就执行下一步,否则继续每隔x秒去判断,指定时间截止。如果超时就会抛出异常。

from selenium import webdriver

from selenium.webdriver.support.ui import Select,WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'/html/body/div[1]/div[1]/div[3]/div[1]/div/button[1]')))

然后去操作元素,本示例是点击

driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[3]/div[1]/div/button[1]').click()

猜你喜欢

转载自www.cnblogs.com/yanding/p/11652670.html