针对页面上的二级菜单,需要鼠标悬停才能进行操作。

/**
* 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 -- 鼠标悬停的更多相关文章

  1. python3 selenium 鼠标悬停操作

    使用场景: 测试过程中有些元素隐藏在某些元素下面,需要鼠标悬停,才会看到 使用方法: # 定位元素hover_element = driver.find_element_by_css_selector ...

  2. Java编程语言下Selenium 鼠标悬停以及右击操作

    // 基于Actions类创建一个对象 Actions action = new Actions(driver); // 鼠标悬停在药渡公司全称字段上 action.moveToElement(Yao ...

  3. selenium鼠标悬停操作

    有些网页一打开会有一个弹窗,弹窗不消失无法进行取元素操作,只有把鼠标悬停在上面弹窗才会消失,这时就用到了selenium的悬停操作 鼠标悬停  move_to_element() 定位到要悬停的元素 ...

  4. python selenium 鼠标悬停

    #鼠标悬停 chain = ActionChains(driver) implement = driver.find_element_by_link_text() chain.move_to_elem ...

  5. selenium鼠标悬停失效,用js语句模拟

    写脚本时,有很多case需要要用的鼠标悬停出菜单 用到了ActionChains(self.driver).move_to_element(el).perform(),但是脚本写完以后,单个case执 ...

  6. Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表

    这两天在玩python中selenium,遇到一个问题,就是鼠标移动到页面中某按钮或菜单,自动弹出二级菜单或下拉菜单,再自动点击其中的二级菜单或下拉列表. 首先,手工操作:打开母校的主页 http:/ ...

  7. Selenium处理页面---弹窗、表格、鼠标悬停、frame、下拉框、上传文件

    一.Selenium测试-常用页面处理 1.概述 UI自动化测试(GUI界面层):UI层是用户使用产品的入口,所有功能通过这一层提供给用户,测试工作大多集中在这一层,常见的测试工具有UFT.Robot ...

  8. 9 Python+Selenium鼠标事件

    [环境信息] python3.6+Selenium3.0.2+Firefox50.0+win7 [ActionChains类鼠标事件的常用方法] 1.右击:context_click() 2.双击:d ...

  9. 自动化测试基础篇--Selenium鼠标键盘事件

    摘自https://www.cnblogs.com/sanzangTst/p/7477382.html 前面几篇文章我们学习了怎么定位元素,同时通过实例也展示了怎么切换到iframe,怎么输入用户名和 ...

随机推荐

  1. 原来zabbix监控进程与端口是如此的简单!

    使用zabbix自带key监控进程与端口 每个公司都有自己的程序,自己的进程名与端口监听,对于nagios来说,这些都经常需要自己去写插件,但是zabbix不需要,它自己就有监控进程与端口的key. ...

  2. C# 在引用插件中 出现的问题| Csharp cite the plugin problem

    背景:使用C#操纵鼠标进行重复性的工作 background: using Csharp to handle the keyboard or mouse to do the repetitive wo ...

  3. Spring IOC - 控制反转(依赖注入) - 单例和多例

    Spring容器管理的bean在默认情况下是单例的,即一个bean只会创建一个对象,存在map中,之后无论获取多少次该bean,都返回同一个对象. Spring默认采用单例方式,减少了对象的创建,从而 ...

  4. gc之六--Minor GC、Major GC、Full GC以及Mixed GC之间的区别

    目录: GC之一--GC 的算法分析.垃圾收集器.内存分配策略介绍 GC之二--GC日志分析(jdk1.8)整理中 GC之三--GC 触发Full GC执行的情况及应对策略 gc之四--Minor G ...

  5. 深入浅出 JIT 编译器

    转载 https://www.ibm.com/developerworks/cn/java/j-lo-just-in-time/ JIT 编译器在运行程序时有两种编译模式可以选择,并且其会在运行时决定 ...

  6. CORS跨域的概念与TP5的解决方案

    namespace app\api\behavior; use think\Response; class CORS{ public function appInit(&$params) { ...

  7. 使用HTML5里页面可见性接口判断用户是否正在观看你的页面

    转自:http://www.webhek.com/page-visibility 长期以来我们一直缺少一个判断用户是否正在浏览某个指定标签页的方法.用户是否去看别的网站了?他们切换回来了么?现在,HT ...

  8. securecrt8注册码

    securecrt8注册码,两个可用 Name:meisiCompany:TEAM ZWTSerial Number:03-14-367662License Key:ACCFAX R9FHJ7 QZV ...

  9. windows CIFS sabma协议识别

    今天在linux上搭建了CIFS协议,使用sabma4.7.0版本. 通过smbstatus可以查看smb软件的版本 通过/bin/smbstatus -d 0可以查看目前正连接的客户端. 问题来了: ...

  10. 内建函数(builtins)和functools

    内建函数 Build-in Function,启动python解释器,输入dir(__builtins__), 可以看到很多python解释器启动后默认加载的属性和函数,这些函数称之为内建函数, 这些 ...