[Selenium]Click element under a hidden element
Description:
Find out the DDL in Treegrid, but cannot click on it.Because the element is under a hidden element.
Have tried all below solutions:
1) theDDL.click();
2) SeleniumUtil.jsClick(driver, theDDL);
3) Actions action = new Actions(driver);
action.moveToElement(theDDL).perform();
4) JavascriptExecutor js = (JavascriptExecutor)driver;
String jsStr = "$('td>div>div:eq("+theDDL+")').click()";
js.executeScript(jsStr);
5) JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", theDDL);
Solution:
In order to click the element ,change it to visible firstly.When we operate manually,actually,we first move the mouse to the row ,and then click the element.
So, when automate the click action,we also need to move the mouse to the row firstly,then the element will be visible,this is the trick.
Hover to the row of DDL, move mouse to the front of the row, then click the DDL would work.
Code:
WebElement theRow = this.findBlankBenchmarkRow();
Assert.assertNotSame(theRow, null, "Should find out a blank benchmark row.");
Actions action = new Actions(driver);
System.out.println("Row size : "+theRow.getSize());
System.out.println(("X offset : "+(theRow.getSize().width)/100));
System.out.println(("Y offset : "+(theRow.getSize().height)/2));
int locx=0;
int locy=0;
locx=(theRow.getSize().width)/100;
locy=(theRow.getSize().height)/2;
action.moveToElement(theRow, locx, locy).perform();
SeleniumUtil.sleep(2);
WebElement theDDL = theRow.findElement(By.cssSelector("td div.dash-bmk-ddl"));
return theDDL;
[Selenium]Click element under a hidden element的更多相关文章
- [Selenium] The commonly used operation of element
btnLogin.click(); //Click element SeleniumUtil.jsClick(driver, saveButtonEl); //If click() ...
- selenium之坑(StaleElementReferenceException: Message: Element not found in the cache...)
有时候循环点击一列链接,只能点到第一个,第二个就失败了 原因是第二个已经是新页面,当然找不到之前页面的元素.就算是后退回来的,页面也是不一样的 页面长的一样不一定是同一张页面,就像两个人长的一样不一定 ...
- selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
抓取网页代码后,由于是在同一个li标签下,所以使用一次性抓取,所有的a标签,然后循环做不同的操作,但是抛出找不到元素异常. def office_page(_chrome: Chrome): sn = ...
- org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element(识别不到想要的元素) 想获取 ...
- select2取值报错,Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.
用到了 select2 组件来多选收件人,用搜狗浏览器(6.2版高速模式)在执行到如下这句时报错(Uncaught InvalidStateError: Failed to read the 'sel ...
- 元素无法定位问题 NoSuchElementException: Message: no such element: Unable to locate element 解决方法
定位网页上某个按钮时,总是报错元素定位不到,具体如下:NoSuchElementException: Message: no such element: Unable to locate elemen ...
- Selenium click不生效 报错selenium.common.exceptions.InvalidArgumentException
记录在使用selenium过程中踩的坑------ 在使用selenium时,用click点击网站弹出的文件上传框的"上传文件"按钮不生效,报错selenium.common.ex ...
- 关于xpath语句完全正确,但是页面报错: no such element: Unable to locate element: {"method":"xpath","selector":"xpath"}
之前使用selenium-webdriver来写UI的自动化脚本,发现有一个元素一直无法定位,查看其源码,如下 利用xpathChecker验证了xpath语句的是正确的,但是控制台一直报错: no ...
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
IE8报错误: 用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .N ...
随机推荐
- Idea 使用 Maven 搭建 Web 项目
传送门: 袁咩咩的小小博客 Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 使用它来搭建项目可以省去很多操作,它不仅有依赖管理.自动生成项目站 ...
- .Net调用Java端带有WS-Security支持的Web Service各方案实战【转】
原文:http://www.xuebuyuan.com/641669.html 到现在为止,我们AEP平台已经发布很长一段时间了,也有很多ISV接入并上线了,就语言而言,目前主要有三类:Java..N ...
- linux python 安装 nose lapack atlas numpy scipy
linux python 安装 nose lapack atlas numpy scipy --http://lib.csdn.net/article/python/1262 作者:maple1149 ...
- (精华)将json数组和对象转换成List和Map(小龙哥和牛徳鹤的对话)
将java标准的数据结构ArrayList和HashMap转换成json对象和数组很简单 只需要JSONArray.fromObject(obj);或者JSONObject.fromObject(ob ...
- macOS -- Mac系统如何编辑hosts文件
Hosts是一个没有扩展名的系统文件,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库",当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Hosts文 ...
- PHP安全性考虑
用户提交的数据 很多PHP 程序所存在的重大弱点并不是PHP 语言本身的问题,而是编程者的安全意识不高而导致的.因此,必须时时注意每一段代码可能存在的问题,去发现非正确数据提交时可能造成的影响. 例子 ...
- phalcon安装笔记
参考官网 git clone --depth= git://github.com/phalcon/cphalcon.git cd cphalcon/build sudo ./install 添加配置文 ...
- Bootstrap学习之路(1)---开篇-登陆页
Bootstrap是现在很流行的一套前端框架,尤其是它的自适应,真的很不错,而且对移动设备也很友好,可以达到快速开发的效果,最近想把自己的网站弄个手机版,很果断的就选用了bootstrap,跟大家分享 ...
- Java 8 新特新 工具类 ZonedDateTime
类ZonedDateTime java.lang.Object继承 java.time.ZonedDateTime 所有实现的接口: Serializable,Comparable < Chro ...
- 迷你MVVM框架 avalonjs 学习教程5、显示隐藏控制
今天的主角是ms-visible,它的效果类拟于jQuery的toggle,如果它后面跟着的表达式为真值时则显示它所在的元素,为假值时则隐藏.不过显示不是 display:none这么简单,众所周知, ...