# Selenium Errors

## ElementClickInterceptedException

通常是由于点击出现了失误，收集了以下几种情况：\
1\. 直接 `.click()` 失效\
2\. 下拉框的出现导致整体的html页面元素位置错乱

解决方法：\
1\. 对于单按钮而言，如“提交”，可以采用发送 ENTER 键的方式代替点击

```python
   Before:
   driver.find_element(By.CSS_SELECTOR,"#submit").click() (X)

   After:
   driver.find_element(By.CSS_SELECTOR,"#submit").send_keys(Keys.ENTER)
```

1. 对于下拉框的选择可以通过执行js模拟鼠标的点击

   ```python
   element = driver.find_element_by_css('xxx')   
   driver.execute_script("arguments[0].click();", element)  

   或 

   element = driver.find_element_by_css('xxx')
   webdriver.ActionChains(driver).move_to_element(element).click(element).perform()
   ```

## ElementNotInteractableException

有时候直接的 `b.find_element_by_xxx('').click()` 可能无效报错 `NotInteractable`，我遇到这种情况通常是需要连续按几个键的时候，上一个键还未失焦而导致无法与新的键交互，这里采用永久覆盖element来保证自己的element。

代码：

```python
(WebElement) ele = driver.findElement(By.xpath("element_xpath"))
driver.execute_script("arguments[0].click();", ele)
```

## Reference

1. [cnblogs | ElementClickInterceptedException](https://www.cnblogs.com/TD1900/p/11955599.html)  &#x20;
2. [cnblogs | UI自动化时，解决selenium中无法点击Element：ElementClickInterceptedException](https://www.cnblogs.com/mihoutao/p/11387659.html) &#x20;
3. [cnblogs | 吴裕雄--天生自然PYTHON学习笔记：解决ELEMENTNOTINTERACTABLEEXCEPTION](https://www.cnblogs.com/tszr/p/12026473.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://legacy.cookielau.com/archives/3-python/3-spider/3-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
