[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 ...
随机推荐
- windows常用DLL及作用
Kernel.dll:内存,硬盘灯硬件管理的相关函数. gdi32.dll:图形显示相关函数(LoadImage,GetPixel,StretchBlt,Ellipse). user32.dll:wi ...
- 输入和输出(read,recv,recvmsg...和write,writev,writemsg)
每一个TCP套接口有一个发送缓冲区,可以用SO_SNDBUF套接口选项来改变这个缓冲区的大小. 应用进程调用 write时,内核从应用进程的缓冲区中拷贝所有数据到套接口的发送缓冲区.如果套接口的发送缓 ...
- 适合Centos Web服务器的iptables规则
适合Centos Web服务器的iptables规则IPT="/sbin/iptables"$IPT --delete-chain$IPT --flush$IPT -P INPUT ...
- 移植wpa_supplicant2.5及界面配置wifi(原创)
JP5G开发机上需要图形界面配置 wifi网络,为此移植了wpa_supplicant2.5. 1.参考wpa_supplicant-2.5移植与使用l http://blog.csdn.net/hk ...
- Web验证方式(2)--Form Authentication
Form验证方式并不是HTTP标准,而是在微软ASP.NET Web框架下提供的一种验证方式.其大致流程如下: 在上图的流程中,ASP.NET框架提供了如下支持类:( FormsAuthenticat ...
- 现在就开始使用AngularJS的三个重要原因
现在就开始使用AngularJS的三个重要原因 在线演示1 本地下载 如果你不熟悉什么是Angular.js的话,小编我强烈推荐你阅读 Javascript教程:AngularJS的五个超酷特性.简单 ...
- python3调用阿里云短信服务
#!/usr/bin/env python#-*- coding:utf-8 -*-#Author:lzd import uuidimport datetimeimport hmacimport ba ...
- PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载 && Linux下的ZipArchive配置开启压缩 &&搞个鸡巴毛,写少了个‘/’号,浪费了一天
PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法就不说了,不同的平台开启PHP扩增的方法网上都有,如有 ...
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #1 如何获取Linux内核
HACK #1 如何获取Linux内核 本节介绍获取Linux内核源代码的各种方法.“获取内核”这个说法看似简单,其实Linux内核有很多种衍生版本.要找出自己想要的源代码到底是哪一个,必须首先理解各 ...
- 好记性不如烂笔头-linux学习笔记3mysql数据库导入导出
1 数据库文件导出 mysqldump -uroot -p123456 test > 1.sql 2数据库文件导入 mysql -uroot -p123456 test <1.sql 3 ...