使用Selenium点击元素时出现element not interactable错误求助
解决Element Not Interactable错误的方案
针对你遇到的element not interactable错误,下面是几种常见的解决思路和代码实现:
等待元素完全可点击
隐式等待仅能确保元素存在,但无法保证元素处于可交互状态。改用显式等待,等待元素满足可点击条件:WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15)); WebElement departureInput = wait.until(ExpectedConditions.elementToBeClickable(By.name("departure[]"))); departureInput.click();滚动到元素可见区域
如果元素不在当前视口内,先滚动到元素位置再尝试点击:WebElement drp = driver.findElement(By.name("departure[]")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", drp); drp.click();使用JavaScript强制点击
若元素因样式隐藏、disabled属性或其他原因无法通过常规方式点击,直接用JS执行点击操作:WebElement drp = driver.findElement(By.name("departure[]")); ((JavascriptExecutor) driver).executeScript("arguments[0].click();", drp);检查页面遮挡元素
确认页面是否有弹窗、加载遮罩层等覆盖在目标元素上,若有需先关闭或等待遮挡元素消失后再操作。
内容的提问来源于stack exchange,提问作者user23718586
相关产品推荐
相关产品推荐

