Selenium ElementClickInterceptedException 错误解决方法 - ddddocr | wenanzhe.com
The error message indicates that the element you are trying to click on is being intercepted by another element. The other element is receiving the click instead of the intended element.\n\nTo fix this issue, you can try the following solutions:\n\n1. Wait for the intercepting element to disappear before clicking on the target element. You can use the WebDriverWait class to wait for the presence of the target element and the absence of the intercepting element.\n\n2. Use JavaScript to click on the element instead of using the click() method of the WebElement. You can execute JavaScript code using the execute_script() method of the WebDriver. \n\nHere's an example of how you can implement the first solution:\n\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\n# Wait for the intercepting element to disappear\nintercepting_element = WebDriverWait(driver, 10).until(\n EC.invisibility_of_element_located((By.XPATH, '//*[@id="intercepting_element_xpath"]'))\n)\n\n# Click on the target element\ntarget_element = WebDriverWait(driver, 10).until(\n EC.element_to_be_clickable((By.XPATH, '//*[@id="target_element_xpath"]'))\n)\ntarget_element.click()\n\n\nReplace '//*[@id="intercepting_element_xpath"]' with the XPath of the intercepting element and '//*[@id="target_element_xpath"]' with the XPath of the target element you want to click on.\n\nIf the above solution doesn't work, you can try the second solution using JavaScript:\n\npython\ntarget_element = WebDriverWait(driver, 10).until(\n EC.element_to_be_clickable((By.XPATH, '//*[@id="target_element_xpath"]'))\n)\n\ndriver.execute_script("arguments[0].click();", target_element)\n\n\nAgain, replace '//*[@id="target_element_xpath"]' with the XPath of the target element.
原文地址: https://www.cveoy.top/t/topic/pSwu 著作权归作者所有。请勿转载和采集!