2 回答
TA贡献1895条经验 获得超3个赞
您需要稍等片刻,Next按钮才会出现。
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
wait = WebDriverWait(driver, 10)
e = wait.until(
EC.presence_of_element_located((By.XPATH, '//*[@id="welcome_button_next"]'))
)
e.click()
TA贡献1804条经验 获得超2个赞
要单击文本为Next的元素,您需要诱导WebDriverWait以使元素可单击,您可以使用以下任一解决方案:
使用CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.btn.btn-primary#welcome_button_next"))).click()
使用XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='btn btn-primary' and @id="welcome_button_next"]"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
添加回答
举报