Selenium Exception: Element is not clickable at point (x, y). Other element would receive the click.

本文介绍了在使用Selenium进行Web自动化测试时,针对元素点击操作的三种优化方案:使用Actions类进行鼠标操作、通过JavaScript滚动元素至可视区域再点击以及直接执行JS点击事件。这些方法能有效解决页面元素不可见或不可交互的问题。

异常:

public void click(WebDriver driver, String className) throws Exception {
	WebElement element = findElement(driver, By.className(className));
	if (element == null) {
		return;
	}
	// 抛出异常
	element.click();
}

解决办法:

  1. 使用 org.openqa.selenium.interactions.Actions
    public void click(WebDriver driver, String className) throws Exception {
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
    		return;
    	}
    	Actions actions = new Actions(driver);
    	actions.moveToElement(buttonElement).click().build().perform();
    }
    
  2. 滚动元素到可视位置
    public void click(WebDriver driver, String className) throws Exception {
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
    		return;
    	}
    	JavascriptExecutor jse = (JavascriptExecutor) driver;
    	jse.executeScript("arguments[0].scrollIntoView()", element);
    	element.click();
    }
    
  3. 直接执行 js 的点击事件
    public void click(WebDriver driver, String className) throws Exception {
    	WebElement element = findElement(driver, By.className(className));
    	if (element == null) {
    		return;
    	}
    	JavascriptExecutor jse = (JavascriptExecutor) driver;
    	jse.executeScript("arguments[0].click();", element);
    }
    

参考

解释这段错误提示并给出解决方案 ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (974, 610). Other element would receive the click: ... (Session info: chrome=142.0.7444.61); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#elementclickinterceptedexception Stacktrace: Symbols not available. Dumping unresolved backtrace: 0x7ff624157a35 0x7ff624157a90 0x7ff623ed16ad 0x7ff623f32359 0x7ff623f2fcde 0x7ff623f2cc11 0x7ff623f2bad0 0x7ff623f1d2c8 0x7ff623f5297a 0x7ff623f1cb56 0x7ff623f7b8fb 0x7ff623f1b068 0x7ff623f1be93 0x7ff6244129d0 0x7ff62440ce50 0x7ff62442cc45 0x7ff6241730ce 0x7ff62417adbf 0x7ff624160c14 0x7ff624160dcf 0x7ff624146828 0x7ffdf663e8d7 0x7ffdf76dc34c Traceback (most recent call last): File "D:\Application\PyCharm2024\MKRTestProject\testCases\testHome.py", line 55, in test_read_more_event home_page_object.read_more_event() File "D:\Application\PyCharm2024\MKRTestProject\pages\homePage.py", line 67, in read_more_event self.clickButton(self.event_read_more_locators[i]) File "D:\Application\PyCharm2024\MKRTestProject\pages\basePage.py", line 32, in clickButton self.findElement(locator).click() File "D:\Application\PyCharm2024\MKRTestProject\.venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 119, in click self._execute(Command.CLICK_ELEMENT) File "D:\Application\PyCharm2024\MKRTestProject\.venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 572, in _execute return self._parent.execute(command, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Application\PyCharm2024\MKRTestProject\.venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 458, in execute self.error_handler.check_response(response) File "D:\Application\PyCharm2024\MKRTestProject\.venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 233, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (974, 610). Other element would receive the click: ... (Session info: chrome=142.0.7444.61); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#elementclickinterceptedexception Stacktrace: Symbols not available. Dumping unresolved backtrace: 0x7ff624157a35 0x7ff624157a90 0x7ff623ed16ad 0x7ff623f32359 0x7ff623f2fcde 0x7ff623f2cc11 0x7ff623f2bad0 0x7ff623f1d2c8 0x7ff623f5297a 0x7ff623f1cb56 0x7ff623f7b8fb 0x7ff623f1b068 0x7ff623f1be93 0x7ff6244129d0 0x7ff62440ce50 0x7ff62442cc45 0x7ff6241730ce 0x7ff62417adbf 0x7ff624160c14 0x7ff624160dcf 0x7ff624146828 0x7ffdf663e8d7 0x7ffdf76dc34c 2025-11-20 17:50:51,098 - testCases.baseTest - INFO - ============================================================ 2025-11-20 17:50:51,098 - testCases.baseTest - INFO - Let's Begin To Start Running The Test Case.
最新发布
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值