问题遇到的现象和发生背景
python + selenium进行自动化填表操作,输入内容时代码自动执行报“element not interactable”错误,但是手动执行这条命令却可以
用代码块功能插入代码,请勿粘贴截图
driver.find_element(By.XPATH, "/html/body/div[5]/div/div[2]/div/div[2]/div[1]/div[2]/div[2]/div[1]/div[2]/div/div/div[1]/div/div/div[12]/div[2]/div/input").send_keys("test")
运行结果及报错内容
Traceback (most recent call last):
File "E:\User\Desktop\python_script\selenium输入测试.py", line 60, in <module>
driver.find_element(By.XPATH, "/html/body/div[5]/div/div[2]/div/div[2]/div[1]/div[2]/div[2]/div[1]/div[2]/div/div/div[1]/div/div/div[12]/div[2]/div/input").send_keys("what the fuck!!!")
File "C:\Users\life\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 223, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\life\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
File "C:\Users\life\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
self.error_handler.check_response(response)
File "C:\Users\life\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=105.0.5195.127)
Stacktrace:
Backtrace:
Ordinal0 [0x0046DF13+2219795]
Ordinal0 [0x00402841+1779777]
Ordinal0 [0x00314100+803072]
Ordinal0 [0x0033E523+976163]
Ordinal0 [0x0033DB93+973715]
Ordinal0 [0x0035E7FC+1107964]
Ordinal0 [0x003394B4+955572]
Ordinal0 [0x0035EA14+1108500]
Ordinal0 [0x0036F192+1175954]
Ordinal0 [0x0035E616+1107478]
Ordinal0 [0x00337F89+950153]
Ordinal0 [0x00338F56+954198]
GetHandleVerifier [0x00762CB2+3040210]
GetHandleVerifier [0x00752BB4+2974420]
GetHandleVerifier [0x00506A0A+565546]
GetHandleVerifier [0x00505680+560544]
Ordinal0 [0x00409A5C+1808988]
Ordinal0 [0x0040E3A8+1827752]
Ordinal0 [0x0040E495+1827989]
Ordinal0 [0x004180A4+1867940]
BaseThreadInitThunk [0x76DAFA29+25]
RtlGetAppContainerNamedObjectPath [0x76F67A9E+286]
RtlGetAppContainerNamedObjectPath [0x76F67A6E+238]
我的解答思路和尝试过的方法
尝试先点击输入框,在进行输入,但是会提示元素不存在
我想要达到的结果
在脚本中,执行这条命令可以输入内容。