Java+Selenium3方法篇29-Actions-划取字段
来源:互联网 发布:新锐软件易制毒电话 编辑:程序博客网 时间:2024/06/05 17:05
本文介绍Actions类下第二个功能,划取字段。我之前做过一个项目,需要在一堆log字符中随机划取一段文字,然后右键选择摘取功能。这篇,就介绍划取字段这个功能,直接看下面的脚本。
package lessons;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.interactions.Actions;public class MyClass {public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.gecko.driver", ".\\Tools\\geckodriver.exe"); WebDriver driver = new FirefoxDriver();driver.manage().window().maximize();driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);driver.get("https://www.baidu.com/duty/");//定义第一段文字WebElement Sting_Sected = driver.findElement(By.xpath("//*/div[@class='dwri_bule']/table/tbody/tr/td/p"));//定义第二段文字WebElement String_Second = driver.findElement(By.xpath("//*/div[@class='dwri_bule']/table/tbody/tr/td/ul/li[1]"));Actions action = new Actions(driver);action.clickAndHold(Sting_Sected).moveToElement(String_Second).perform();action.release();}}
在上面代码里定义了两个元素element1 和element2,element1是定位在最顶端的那段文字,element2是定义下面第一小点的文字。功能原理就是,找到顶端那个文字,然后按下鼠标不动,移动到element2然后释放鼠标,在实际过程中,会随机划取element1到element2直接的文字,划多少文字,没法确定。
我这边运行效果
阅读全文
0 0
- Java+Selenium3方法篇29-Actions-划取字段
- Java+Selenium3方法篇28-Actions-鼠标悬停
- Java+Selenium3方法篇33-Actions-拖拽操作
- Java+Selenium3方法篇28-Actions-鼠标悬停
- 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
- Java+Selenium3方法篇10-findElement之By PartialLinkText
- “情绪地图”:当你感受快乐时,你的身体感受些什么
- 架构师之路(八)
- numpy.linalg学习
- Linux安装
- leetcode593. Valid Square
- Java+Selenium3方法篇29-Actions-划取字段
- Maven仓库(从仓库解析依赖的机制)
- jQuery动态设置select选中值
- ORACLE初学第五篇
- 快速排序
- 关于ssm整合过程中,spring配置文件无提示功能
- QRound的使用总结
- html 输入框 只能输入数字 只能输入字母数字组合
- ANDROID-Interface