Java+Selenium3方法篇28-Actions-鼠标悬停
来源:互联网 发布:怎样变更淘宝店的地区 编辑:程序博客网 时间:2024/06/05 15:43
有些事件,Selenium没有直接提供方法去操作,像鼠标悬停,一般测试场景鼠标悬停分两种常见,一种是鼠标悬停在某一个元素上方,然后会出现下拉子菜单,第二种就是在搜索输入过程,选择自动补全的字段。关于鼠标悬停,selenium把这个方法放在了Actions.java文件中,先来看看鼠标悬停出现下拉菜单的情况。
package lessons;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;public class ElementOpration {public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.baidu.com/"); Thread.sleep(2000); // 设置 WebElement settings = driver.findElement(By.xpath("//*[@id='u1']/a[8]")); Actions action = new Actions(driver); action.moveToElement(settings).perform(); driver.findElement(By.linkText("高级搜索")).click(); } }再来看看搜索输入,选择自动补全的字段如何自动化实现。
package lessons;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;public class ElementOpration {public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.baidu.com/"); Thread.sleep(1000); // 设置 WebElement inputbox = driver.findElement(By.id("kw")); inputbox.sendKeys("selenium a"); // 自动补全其中一个选择项 WebElement auto_text = driver.findElement(By.xpath("//*[@id='form']/div/ul/li[@data-key='selenium api文档']")); Actions action = new Actions(driver); action.moveToElement(auto_text).click().perform();}}Actions类中鼠标悬停方法就介绍到这里。
阅读全文
0 0
- Java+Selenium3方法篇28-Actions-鼠标悬停
- Java+Selenium3方法篇28-Actions-鼠标悬停
- Java+Selenium3方法篇29-Actions-划取字段
- Java+Selenium3方法篇33-Actions-拖拽操作
- Selenium3.x Python实现鼠标悬停的几种方法
- Java+Selenium3方法篇25-isDisplayed方法
- Java+Selenium3方法篇13-findElements举例
- Java+Selenium3方法篇39-Explicit wait
- Java+Selenium3方法篇41-FluentWait
- Java+Selenium3方法篇2-Timeout接口相关方法介绍
- Java+Selenium3方法篇3-window接口相关方法介绍
- Java+Selenium3方法篇30-Selenium中截图方法-TakeScreenshot
- Java+Selenium3方法篇4-Navigation接口介绍
- Java+Selenium3方法篇5-findElement之By id
- Java+Selenium3方法篇6-findElement之By XPath
- Java+Selenium3方法篇7-findElement之By LinkText
- Java+Selenium3方法篇8-findElement之By ClassName
- Java+Selenium3方法篇9-findElement之By Name
- BIEE 12c客户化报表导出菜单项
- 21、参数的传递
- 小M开发_java零基础(字母金字塔案例)
- 2017-06-27 第一次写博客
- PDB的plugging和unpluged
- Java+Selenium3方法篇28-Actions-鼠标悬停
- webpack引入jquery
- 信号
- Java 工厂方法模式
- nginx配置和tomcat的集成
- 22、动态 SQL
- 实战
- 23、Mapper解析之基于注解的总体过程
- ffmpeg参数