在selenium webdriver学习(十)------------如何把一个元素拖放到另一个元素里面的时候,用到了一个Actions类。这一节主要分析一下这个Actions类。
这个actions类,主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作。对于这些操作,使用perform()方法进行执行。
actions类可以完成单一的操作,也可以完成几个操作的组合。
单一的操作
单一的操作是指鼠标和键盘的一个操作。如鼠标左键按下、弹起或输入一个字符串等。
前面涉及到鼠标键盘操作的一些方法,都可以使用actions类中的方法实现,比如:click,sendkeys。
-
WebElementelement=dr.findElement(By.id("test"));
-
WebElementelement1=dr.findElement(By.id("test1"));
-
element.sendKeys("test");
-
element1.click;
用Actions类就可以这样实现:
-
-
Actionsaction=newActions(driver);
-
-
WebElementelement=dr.findElement(By.id("test"));
-
WebElementelement1=dr.findElement(By.id("su"));
-
action.sendKeys(element,"test").perform();
-
action.moveToElement(element1);
-
action.click().perform();
看起来用Actions类实现click和sendKeys有点烦索
组合操作
组合操作就是几个动作连在一起进行操作。如对一个元素的拖放。
-
(newActions(dr)).dragAndDrop(dr.findElement(By.id(item)),target).perform();
可以直接调用dragAndDrip()方法,也可以像下面濱示的一样把几个操作放一起实现
-
ActiondragAndDrop=builder.clickAndHold(someElement)
-
.moveToElement(otherElement)
-
.release(otherElement)
-
.build().perform();
其他鼠标或键盘操作方法可以具体看一下API里面的org.openqa.selenium.interactions.Actions
原文:http://jarvi.iteye.com/blog/1468690
分享到:
相关推荐
Selenium WebDriver Practical Guide will guide you through the various APIs of WebDriver which should be used in automation tests, followed by a discussion of the various WebDriver implementations ...
Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations...
Increase the performance, capability, and reliability of your automated checks by mastering Selenium WebDriver About This Book Create an extensible test framework in Java supporting parallel ...
Selenium WebDriver 3.x is an open source API for testing both browser and mobile applications. With the help of this book, you can build a solid foundation and can easily perform end-to-end testing on...
此操作旨在使用 Github Actions 运行 selenium webdriver 测试(任何语言、任何框架) Selenoid 服务器与 selenium-standalone 完全兼容,可以作为直接替代品使用。 完整文档在这里: : 使用 CM 工具下载和配置 ...
webdriver crate upgraded to 0.38.0. Fixed desiredCapabilities and requiredCapabilities are again recognised on session creation A regression in 0.22.0 caused geckodriver to recognise desired and ...
webdriver下 如何模拟右键菜单操作?action.contextClick(element)命令可实现鼠标右键点击操作,例如: Actions action = new Actions(driver) ; action.contextClick(driver.findElement(By.xpath("//div/li/div/...
此操作设置了一个以在操作中使用 操作系统/平台支持 ubuntu-latest、ubuntu-20.04、ubuntu-18.04 或 ubuntu-16.04 macos-最新,macos-10.15 windows-最新,windows-2019 用法 参见 对于 ubuntu-latest、macos-...
package util; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.... * 模拟鼠标左键单击 * @param driver * @param xpathExpression */ public void lefCl
Linkedin刮板机 ...from selenium import webdriver driver = webdriver . Chrome () email = "some-email@email.address" password = "password123" actions . login ( driver , email , password ) # if emai
如果将ReactJS与Storybook和来自Webdriver IO的可视化回归测试相结合,则可以创建一个设计系统和一个自定义组件库,可以在产品和/或其他团队之间安全地重用它们。 有时,当在一个大团队或多个团队中共享一个UI库时...
浏览器由WebDriver控制。 | | | | | | | | | | | | | | | | :white_heavy_check_mark: 具有用于Web-UI测试的 。 :white_heavy_check_mark: 展开pytest 。 :white_heavy_check_mark: 包括用于驱动程序管理的。 :...
tuscblackchamber.org 网站