selenium -- 鼠标悬停
针对页面上的二级菜单,需要鼠标悬停才能进行操作。
/**
* Clicks (without releasing) in the middle of the given element. This is equivalent to:
* <i>Actions.moveToElement(onElement).clickAndHold()</i>
*
* @param onElement Element to move to and click.
* @return A self reference.
*/
public Actions clickAndHold(WebElement onElement) {
action.addAction(new ClickAndHoldAction(mouse, (Locatable) onElement));
return this;
}
使用方法:最后一定不要忘记perform()
Actions actions = new Actions(driver);
actions.clickAndHold(webElement).perform();
或者:
Actions actions = new Actions(driver);
actions.moveToElement(webElement).clickAndHold().perform();
或者:使用js来模拟鼠标悬停
/**
* JScript实现鼠标悬停
* @author lozz
*/
public void mouseHoverJScript(WebElement HoverElement) {
// TODO Auto-generated method stub
try {
if (isElementPresent(HoverElement)) {
String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
((JavascriptExecutor) driver).executeScript(mouseOverScript, HoverElement);
} else {
System.out.println("Element was not visible to hover " + "\n");
}
} catch (StaleElementReferenceException e) {
// TODO: handle exception
System.out.println("Element with " + HoverElement + "元素未附加到页面文档" + e.getStackTrace());
} catch (NoSuchElementException e) {
// TODO: handle exception
System.out.println("Element " + HoverElement + " 元素未在DOM中没有找到" + e.getStackTrace());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("悬停时发生错误" + e.getStackTrace());
}
}
--- 转载请说明来源 ,thx
selenium -- 鼠标悬停的更多相关文章
- python3 selenium 鼠标悬停操作
使用场景: 测试过程中有些元素隐藏在某些元素下面,需要鼠标悬停,才会看到 使用方法: # 定位元素hover_element = driver.find_element_by_css_selector ...
- Java编程语言下Selenium 鼠标悬停以及右击操作
// 基于Actions类创建一个对象 Actions action = new Actions(driver); // 鼠标悬停在药渡公司全称字段上 action.moveToElement(Yao ...
- selenium鼠标悬停操作
有些网页一打开会有一个弹窗,弹窗不消失无法进行取元素操作,只有把鼠标悬停在上面弹窗才会消失,这时就用到了selenium的悬停操作 鼠标悬停 move_to_element() 定位到要悬停的元素 ...
- python selenium 鼠标悬停
#鼠标悬停 chain = ActionChains(driver) implement = driver.find_element_by_link_text() chain.move_to_elem ...
- selenium鼠标悬停失效,用js语句模拟
写脚本时,有很多case需要要用的鼠标悬停出菜单 用到了ActionChains(self.driver).move_to_element(el).perform(),但是脚本写完以后,单个case执 ...
- Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表
这两天在玩python中selenium,遇到一个问题,就是鼠标移动到页面中某按钮或菜单,自动弹出二级菜单或下拉菜单,再自动点击其中的二级菜单或下拉列表. 首先,手工操作:打开母校的主页 http:/ ...
- Selenium处理页面---弹窗、表格、鼠标悬停、frame、下拉框、上传文件
一.Selenium测试-常用页面处理 1.概述 UI自动化测试(GUI界面层):UI层是用户使用产品的入口,所有功能通过这一层提供给用户,测试工作大多集中在这一层,常见的测试工具有UFT.Robot ...
- 9 Python+Selenium鼠标事件
[环境信息] python3.6+Selenium3.0.2+Firefox50.0+win7 [ActionChains类鼠标事件的常用方法] 1.右击:context_click() 2.双击:d ...
- 自动化测试基础篇--Selenium鼠标键盘事件
摘自https://www.cnblogs.com/sanzangTst/p/7477382.html 前面几篇文章我们学习了怎么定位元素,同时通过实例也展示了怎么切换到iframe,怎么输入用户名和 ...
随机推荐
- JSSDK微信自定义分享朋友圈
服务项目 新手技术咨询 企业技术咨询 定制开发 服务说明 QQ有问必答 QQ.微信.电话 微信开发.php开发,网站开发,系统定制,小程序开发 价格说明 200元/月 1000/月 商议 ...
- java判断字符串中是否含有中文
/** * 判断字符串中是否含有中文 */ public static boolean isCNChar(String s){ boolean booleanValue = false; for(in ...
- 2018-2019 20165226 Exp6 信息搜集与漏洞扫描
2018-2019 20165226 Exp6 信息搜集与漏洞扫描 目录 一.实验内容说明及基础问题回答 二.实验过程 Task1 各种搜索技巧的应用 检测特定类型的文件 搜索网址目录结构 trace ...
- spark api之二:常用示例
1.启动spark shell,在doc窗口上打开spark-shell(环境安装见:二.Spark在Windows下的环境搭建) 并行化scala集合(Parallelize) //加载数据1~10 ...
- Java堆外内存之四:直接使用Unsafe类操作堆外内存
在nio以前,是没有光明正大的做法的,有一个work around的办法是直接访问Unsafe类.如果你使用Eclipse,默认是不允许访问sun.misc下面的类的,你需要稍微修改一下,给Type ...
- var abc = function(x){} 和 function abc(x){}的区别
转自百度知道. 问:js里声明函数有几种方式? var abc = function(x){} 和 function abc(x){} 这两种声明方法有什么不同? 答:首先后者是指函数声明,前者是指函 ...
- Linux修改本地时间
1.Linux时间调整 1)安装ntp(目的同步时间) yum install ntp 2)修改文件 vi /etc/ntp.conf 添加 server ntp.sjtu.edu.cn perfer ...
- delphi WebBrowser的使用方法详解(四)-webbrowser轻松实现自动填表
webbrowser轻松实现自动填表 步骤如下: 第一步:获取网页 调用Webbrowser 的Navigate系列函数.等待网页装载完成,得到document对象. 在调用 webBrowser. ...
- Android ffmpeg rtmp(source code)
souce code: Android.mk 编译生成APK需要调用的so文件 LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODU ...
- Executor框架(二)Executor 与 ExecutorService两个基本接口
一.Executor 接口简介 Executor接口是Executor框架的一个最基本的接口,Executor框架的大部分类都直接或间接地实现了此接口. 只有一个方法 void execute(Run ...