python selenium Exception:element not interactable

在使用Python的Selenium库进行自动化测试时,遇到了ElementNotInteractableException错误,原因是尝试点击的元素是一个不支持点击事件的Div。解决方案是通过执行JavaScript来模拟点击。此外,还涉及到Chrome浏览器的版本更新和滑块验证等自动化测试挑战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D:\software\python3\python.exe C:\Users\h220406010\AppData\Roaming\JetBrains\IntelliJIdea2021.1\plugins\python\helpers\pydev\pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 52944 --file E:/myworkspace/nanxiuzi_learn/baserocks/python/Selenium/test_login.py
C:\Users\h220406010\AppData\Roaming\JetBrains\IntelliJIdea2021.1\plugins\python\helpers\pydev\pydevd.py:1844: DeprecationWarning: currentThread() is deprecated, use current_thread() instead
  dummy_thread = threading.currentThread()
Connected to pydev debugger (build 211.7442.40)
E:/myworkspace/nanxiuzi_learn/baserocks/python/Selenium/test_login.py:31: DeprecationWarning: use options instead of chrome_options
  self.driver = webdriver.Chrome(chrome_options=chrome_options)
INFO:root:滑块验证,尝试第 1 次
ERROR:root:登录成功了
INFO:root:恭喜铁子,登录成功,页面跳转中 
该元素是否显示:False
Traceback (most recent call last):
  File "E:/myworkspace/nanxiuzi_learn/baserocks/python/Selenium/test_login.py", line 183, in <module>
    login.test_login()
  File "E:/myworkspace/nanxiuzi_learn/baserocks/python/Selenium/test_login.py", line 156, in test_login
    ele.click()
  File "D:\software\python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 81, in click
    self._execute(Command.CLICK_ELEMENT)
  File "D:\software\python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 740, in _execute
    return self._parent.execute(command, params)
  File "D:\software\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
    self.error_handler.check_response(response)
  File "D:\software\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=100.0.4896.88)
Stacktrace:
Backtrace:
	Ordinal0 [0x00927413+2389011]
	Ordinal0 [0x008B9F61+1941345]
	Ordinal0 [0x007AC520+836896]
	Ordinal0 [0x007DA1F3+1024499]
	Ordinal0 [0x007CFF93+982931]
	Ordinal0 [0x007F414C+1130828]
	Ordinal0 [0x007CF974+981364]
	Ordinal0 [0x007F4364+1131364]
	Ordinal0 [0x00804302+1196802]
	Ordinal0 [0x007F3F66+1130342]
	Ordinal0 [0x007CE546+976198]
	Ordinal0 [0x007CF456+980054]
	GetHandleVerifier [0x00AD9632+1727522]
	GetHandleVerifier [0x00B8BA4D+2457661]
	GetHandleVerifier [0x009BEB81+569713]
	GetHandleVerifier [0x009BDD76+566118]
	Ordinal0 [0x008C0B2B+1968939]
	Ordinal0 [0x008C5988+1989000]
	Ordinal0 [0x008C5A75+1989237]
	Ordinal0 [0x008CECB1+2026673]
	BaseThreadInitThunk [0x766BFA29+25]
	RtlGetAppContainerNamedObjectPath [0x773C7A7E+286]
	RtlGetAppContainerNamedObjectPath [0x773C7A4E+238]


Process finished with exit code 1

错误内容:元素没有交互能力

报错行:ele.click()

原因:这个是Div ,不拥有点击事件

解决办法:

self.driver.execute_script("arguments[0].click();", ele.find_elements(by=By.XPATH,value='./*')[0])

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南修子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值