Selenium: Wait for Element to Appear Before Clicking with Explicit Wait
To wait for the element to appear before clicking on it, you can use an explicit wait. Here's an example:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10) # Wait for a maximum of 10 seconds
element = wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[3]/div/div[2]/div/form/div[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div/div/div/div[1]/span/span/i')))
element.click()
This code will wait for the element to be visible on the page for a maximum of 10 seconds before clicking on it. Adjust the timeout value (10 in this example) according to your needs.
原文地址: https://www.cveoy.top/t/topic/pmzU 著作权归作者所有。请勿转载和采集!