【转】Selenium 报错:Element is not clickable at point的解决办法
天一同学在写Selenium Java脚本时遇到一个问题,登录进入系统之后,要点击左侧的一个菜单,但是执行到该语句时报下面的错误:
Firefox中报错如下:
org.openqa.selenium.ElementClickInterceptedException: Element <div class="el-submenu__title"> is not clickable at point (115,358) because another element <div class="el-loading-mask is-fullscreen el-loading-fade-leave-active el-loading-fade-leave-to"> obscures it
错误的意思是:无法点击这个元素,因为被另一个div掩盖(obscure)住了。
Chrome 中报错如下:
org.openqa.selenium.WebDriverException: unknown error: Element <div class="el-submenu__title" style="padding-left: 20px;">...</div> is not clickable at point (115, 358). Other element would receive the click: <div class="el-loading-mask is-fullscreen el-loading-fade-leave-active el-loading-fade-leave-to" style="z-index: 2000;">...</div>
(Session info: chrome=67.0.3396.99)
错误的意思是:无法点击这个元素,另外一个div元素接收了这个点击。
经分析调试,以下方法可以解决此类问题。
解决方法一:
思路:先使用invisibilityOf等待掩盖的div消失不见,再使用elementToBeClickable等待要点击的元素达到可点击的状态。
示例:
//要点击的左侧菜单元素
WebElement LeftMenu = driver.findElement(By.xpath("xpath"));
//掩盖的div元素
WebElement ObscureDiv = driver.findElement(By.xpath("//div[@class='el-loading-mask is-fullscreen el-loading-fade-leave-active el-loading-fade-leave-to']"));
//使用显示等待,等待掩盖的div消失
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.invisibilityOf(ObscureDiv));
//等待左侧菜单到可点击状态
wait.until(ExpectedConditions.elementToBeClickable(LeftMenu ));
//之后再执行点击
LeftMenu .click();
解决方法二:
思路:因为掩盖的div可能会在进行一些操作后,会消失,所以登录后执行一个页面刷新的操作,此div即可消失。
再等待左侧菜单到可点击状态即可。
示例:
//登录之前的代码
//登录后加时间等待,并且进行一次页面刷新
Thread.sleep(3000);
driver.navigate().refresh();
//要点击的左侧菜单元素
WebElement LeftMenu = driver.findElement(By.xpath("xpath"));
//等待左侧菜单到可点击状态
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.elementToBeClickable(LeftMenu ));
//之后再执行点击
LeftMenu .click();
****************************************************************************************************
最近我会持续更新Selenium Java的相关文章,也请大家多多关注我的视频课程
全网最新、最完整、最具性价比、并且会持续保持更新的自动化测试课程
Selenium3 Java自动化测试完整教程
*****************************************************************************************************
关注火烈鸟测试公众号:huolieniaotesting,我会在上面更新一些关于测试的文章,我经常会逛一些国外的论坛,也会把比较好的国外专家的文章及国外测试动态分享到这个公众号里,让大家可以了解到国外的测试情况,也希望大家能在上面发表文章,聊聊测试那些事儿。
解决思路:
错误Element is not clickable at point (x, y)可能源于不同因素。您可以通过以下任一过程解决它们:
1.由于存在JavaScript或AJAX调用,元素未被点击
尝试使用ActionsClass:
WebElement element = driver.findElement(By.id("navigationPageButton"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
2.元素未被点击,因为它不在视口内
尝试使用JavascriptExecutor该元素在视口中:
WebElement myelement = driver.findElement(By.id("navigationPageButton"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement);
3.在元素可点击之前,页面将被刷新。
在这种情况下,如第4点所述诱导ExplicitWait即WebDriverWait。
4.元素存在于DOM中但不可点击。
在这种情况下, 请将ExplicitWaitExpectedConditions设置elementToBeClickable为可单击的元素:
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
5.元素存在但具有临时叠加。
在这种情况下,ExplicitWait使用 ExpectedConditionsset设置invisibilityOfElementLocated为Overlay是不可见的。
WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
6.元素存在但具有永久叠加。
用于JavascriptExecutor直接在元素上发送单击。
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
【转】Selenium 报错:Element is not clickable at point的解决办法的更多相关文章
- selenium报错Element is not clickable at point及四种解决方法
使用Selenium时,触发点击事件,经常报如下异常:Element is not clickable at point 1.未加载没加载出来就等待元素加载出来,再往下执行.可以使用python库ti ...
- excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法 office2007应该遇到“向程序发送命令时出现 问题”,设置为以管理员运行也不好用,重装office也不好用,下面介绍下 ...
- CocoaPods pod install的时候报错:invalid byte sequence in UTF-8 (ArgumentError)解决办法
CocoaPods pod install的时候报错:invalid byte sequence in UTF-8 (ArgumentError)解决办法: 基本可以确定是Podfile中的内容编码有 ...
- 转 : Apache启动报错:could not bind to address [::]:443 解决办法
转:Apache启动报错:could not bind to address [::]:443 解决办法 安装Apache服务器的时候,报如下错误: Installing the 'apache' s ...
- Scrapy安装报错 Microsoft Visual C++ 14.0 is required 解决办法
Scrapy安装报错 Microsoft Visual C++ 14.0 is required 解决办法原因:Scrapy需要的组 twisted 需要 C++环境编译. 方法一:根据错误提示去对应 ...
- adb shell报错:error: insufficient permissions for device的解决办法
1.错误描述 执行 adb shell 时,报错如下; error: insufficient permissions for device 2.解决办法 1,终端执行 lsusb 结果如下,注意绿 ...
- Win7 64bit 安装VisualSVN出现报错:Servic 'VisualSVN Server' failed to start.解决办法
问题描述: Win7 64bit 安装VisualSVN时出现报错: Servic 'VisualSVN Server' failed to start.Please check VisualSVN ...
- AXIS-web.xml里配置axis报错addChild: Child name 'AxisServlet' is not unique 解决办法
报错这个那么就表示,web.xml中有相同的AxisServlet的这个名字,可以把原来的删除配置自己的,也可以保留原来的,自己的不配置 Ctrl+f 搜索下就知道了
- java开发过程中,报错Dangling meta character '*' near index 0,解决办法
1.split方法转化字符串为数组: String[] strPicArr = map.get("hw_pic").toString().split("*"); ...
随机推荐
- Spring Boot 实战 入门
目前没有系统学习过 Spring 框架,参与工作时,直接参与到了 Spring Boot 项目的开发.目前还比较菜,所以,你要是和我一样,不妨也跳过 Spring 框架的学习,直接学习 Sring B ...
- Navicat连接mysql报错1862
昨天重新设置了mysql的密码 因为之前一直都是不用密码登录的 因为是公司数据库还是要密码 但是加了密码我今天打开 然后再控制台重新设置一下密码就好了 mysql -u root -p SET PAS ...
- current transaction is aborted, commands ignored until end of transaction block
current transaction is aborted, commands ignored until end of transaction block Error updating datab ...
- Solr缓存原理分析及配置优化
一.缓存原理 缓存,带来急速性能体验! Solr提供了一系列的内置缓存来优化查询性能.Solr的缓存原理主要涉及以下4个方面: 1.缓存大小及缓存置换法 从缓存大小的角度来看,不能将缓存设置的太大,否 ...
- 人生物语——哲海拾贝
如今的这个社会,物欲横流.纸醉金迷.浮躁不安是这个时代的主旋律,在这样一个浮华年代的大染缸里,每个人内心都有那么一颗浮躁不安分的种子,或许它才开始发芽,或许它已经占据了你的心灵,人生当中追求 ...
- 编译3516cv500 osdrv失败解决
configure: WARNING: cannot find uuid library required for mkfs.ubifsconfigure: mtd-utils can optiona ...
- Android: Error inflating class android.support.v4.view.ViewPager 问题的解决方法
ViewPager是个很好很强大的控件,很多应用用它来实现很酷的效果,但是很多情况下在运行时会遇到Error inflating class android.support.v4.view.ViewP ...
- Docker Compose YML文件配置
Docker Compose YML 默认的模板文件是 docker-compose.yml,其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来 ...
- redisTemplate 键值序列化策略
redisTemplate 键值序列化策略 RedisSerializer<T> StringRedisSerializer JdkSerializationRedisSerializer ...
- electron/nodejs实现调用golang函数
https://www.jianshu.com/p/a3be0d206d4c 思路 golang 支持编译成c shared library, 也就是系统中常见的.so(windows下是dll)后缀 ...