在使用chromedriver进行测试时,因对浏览器的宽和高进行了设置(480, 800),当欲点击某一控件,而该控件未显示在当前页面的可见范围内,需要滚动页面至某处方可显示时,会报WebDriverException: Message: unknown error: Element is not clickable at point (x, x). Other element would receive the click错误,即元素在坐标点(x, x)处不可点击,其他元素会接收到此点击(因元素被遮挡,或“不可见”)。

自动化测试——解决Element is not clickable at point (x, x). Other element would receive the click

自动化测试——解决Element is not clickable at point (x, x). Other element would receive the click

解决办法:1.重新调整浏览器的大小,保证欲点击的控件在点击操作执行时“可见”;2.在点击执行前对页面进行滚动操作,使得该控件在页面上显示出来。针对第二种解决办法,可以通过利用ActionChains解决此问题。

代码如下:

from selenium.webdriver.common.action_chains import ActionChains

# 欲点击的未显示的控件在页面底部(顶部略)时,将页面滚动至底部
ActionChains(driver).send_keys(Keys.END).perform()
# 执行点击操作
Link.click()

 

相关文章: