selenium元素定位问题-元素可以被定位到但是无法点击?
报错信息如下【截取片段】:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <span>...</span> is not clickable at point (1040, 283). Other element would receive the click: <button type="button" class="ant-btn ant-btn-primary">...</button>
(Session info: chrome=108.0.5359.124)
原因:
可能是点击事件被父级元素拦截了,于是将要选中的选项的xpath路径改为上一层
例如:
<button data-v-2215c164="" type="button" class="ant-btn ant-btn-primary" ant-click-animating-without-extra-node="false">
<span>通 过</span>
</button>
通过元素定位进行点击操作:
- 若定位表达式为:
# 表示元素element指向span的父级button元素,那么点击事件可以被触发
//span[contains(text(),"通 过")]/parent::button
- 若定位表达式为:
# 表示元素element指向span元素,但是span元素可能未包含在点击事件触发条件内,不被允许,被父级拦截无法触发点击
//span[contains(text(),"通 过")]