Selenium 报错:元素点击被拦截 - 解决方案
这个报错是由于在点击元素时,被其他元素阻挡导致无法点击。根据错误信息,被阻挡的元素是一个id为"footer"的div。\n\n解决这个问题的方法有几种:\n\n1. 使用WebDriverWait等待页面加载完成后再点击元素,确保元素可点击。\npython\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\nfrom selenium.webdriver.common.by import By\n\nwait = WebDriverWait(driver, 10)\nelement = wait.until(EC.element_to_be_clickable((By.ID, "iShowSkip")))\nelement.click()\n\n\n2. 使用JavaScript点击元素,绕过元素被阻挡的问题。\npython\nelement = driver.find_element_by_id("iShowSkip")\ndriver.execute_script("arguments[0].click();", element)\n\n\n3. 使用ActionChains模拟鼠标操作,先移动到元素位置再点击。\npython\nfrom selenium.webdriver.common.action_chains import ActionChains\n\nelement = driver.find_element_by_id("iShowSkip")\nactions = ActionChains(driver)\nactions.move_to_element(element).click().perform()\n\n\n尝试这些方法中的任何一个都可能解决你遇到的问题。
原文地址: https://www.cveoy.top/t/topic/p5Pr 著作权归作者所有。请勿转载和采集!