Java 类org.openqa.selenium.interactions.Action 实例源码
项目:ats-framework
文件:HiddenHtmlElement.java
/**
* Drag and drop an element on top of other element
* @param targetElement the target element
*/
@Override
@PublicAtsApi
public void dragAndDropTo(
HtmlElement targetElement ) {
new HiddenHtmlElementState(this).waitToBecomeExisting();
WebElement source = HiddenHtmlElementLocator.findElement(this);
WebElement target = HiddenHtmlElementLocator.findElement(targetElement);
Actions actionBuilder = new Actions(htmlUnitDriver);
Action dragAndDropAction = actionBuilder.clickAndHold(source)
.moveToElement(target, 1, 1)
.release(target)
.build();
dragAndDropAction.perform();
// drops the source element in the middle of the target, which in some cases is not doing drop on the right place
// new Actions( htmlUnitDriver ).dragAndDrop( source, target ).perform();
}
项目:ats-framework
文件:RealHtmlElement.java
/**
* Drag and drop an element on top of other element
* @param targetElement the target element
*/
@Override
@PublicAtsApi
public void dragAndDropTo(
HtmlElement targetElement ) {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement source = RealHtmlElementLocator.findElement(this);
WebElement target = RealHtmlElementLocator.findElement(targetElement);
Actions actionBuilder = new Actions(webDriver);
Action dragAndDropAction = actionBuilder.clickAndHold(source)
.moveToElement(target, 1, 1)
.release(target)
.build();
dragAndDropAction.perform();
// drops the source element in the middle of the target, which in some cases is not doing drop on the right place
// new Actions( webDriver ).dragAndDrop( source, target ).perform();
}
项目:seleniumcapsules
文件:DragAndDropTest.java
@Test
public void dragAndDropFirefox() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
WebElement source = driver.findElement(id("drag1"));
System.out.println(source.getAttribute("src"));
WebElement target = driver.findElement(id("div2"));
System.out.println(target.getTagName() + "=" + target.toString());
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(source)
.moveToElement(target)
.release(source)
.build();
dragAndDrop.perform();
}
项目:seleniumcapsules
文件:DragAndDropTest.java
@Test
public void dragAndDropChrome() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
WebElement source = driver.findElement(id("drag1"));
System.out.println(source.getAttribute("src"));
WebElement target = driver.findElement(id("div2"));
System.out.println(target.getTagName() + "=" + target.toString());
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(source)
.moveToElement(target)
.release(source)
.build();
dragAndDrop.perform();
}
项目:seleniumcapsules
文件:DragAndDropTest.java
@Test
public void dragAndDropSafari() throws InterruptedException {
WebDriver driver = new SafariDriver();
driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
WebElement source = driver.findElement(id("drag1"));
System.out.println(source.getAttribute("src"));
WebElement target = driver.findElement(id("div2"));
System.out.println(target.getTagName() + "=" + target.toString());
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(source)
.moveToElement(target)
.release(source)
.build();
dragAndDrop.perform();
}
项目:selendroid
文件:TouchFlickTest.java
@Test
public void testCanFlickVerticallyFromWebElement() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link3"));
int y = link.getLocation().y;
// The element is located at the bottom of the page,
// so it is not initially visible on the screen.
assertTrue(y > 4200);
WebElement toFlick = driver().findElement(By.id("imagestart"));
Action flick = getBuilder(driver()).flick(toFlick, 0, -600, FlickAction.SPEED_NORMAL).build();
flick.perform();
y = link.getLocation().y;
// After flicking, the element should now be visible on the screen.
assertTrue("Expected y < 4000, but got: " + y, y < 4000);
}
项目:selendroid
文件:TouchFlickTest.java
@Test
public void testCanFlickVerticallyFastFromWebElement() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link4"));
int y = link.getLocation().y;
// The element is located at the bottom of the page,
// so it is not initially visible on the screen.
assertTrue(y > 8700);
WebElement toFlick = driver().findElement(By.id("imagestart"));
Action flick = getBuilder(driver()).flick(toFlick, 0, -600, FlickAction.SPEED_FAST).build();
flick.perform();
y = link.getLocation().y;
// After flicking, the element should now be visible on the screen.
assertTrue("Expected y < 8700, but got: " + y, y < 8700);
}
项目:selendroid
文件:TouchFlickTest.java
@Test
public void testCanFlickVertically() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link3"));
int y = link.getLocation().y;
// The element is located at the bottom of the page,
// so it is not initially visible on the screen.
assertTrue(y > 4200);
Action flick = getBuilder(driver()).flick(0, 750).build();
flick.perform();
y = link.getLocation().y;
// After flicking, the element should now be visible on the screen.
assertTrue("Got: " + y, y < 4200);
}
项目:selendroid
文件:TouchFlickTest.java
@Test
public void testCanFlickVerticallyFast() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link4"));
int y = link.getLocation().y;
// The element is located at the bottom of the page,
// so it is not initially visible on the screen.
assertTrue(y > 8700);
Action flick = getBuilder(driver()).flick(0, 1500).build();
flick.perform();
y = link.getLocation().y;
// After flicking, the element should now be visible on the screen.
assertTrue("Got: " + y, y < 4000);
}
项目:selendroid
文件:TouchScrollTest.java
@Test
public void testCanScrollVerticallyFromWebElement() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link3"));
int y = link.getLocation().y;
// The element is located at the right of the page,
// so it is not initially visible on the screen.
assertTrue("Expected y > 4200, but got y = " + y, y > 4200);
WebElement toScroll = driver().findElement(By.id("imagestart"));
Action scroll = getBuilder(driver()).scroll(toScroll, 0, -800).build();
scroll.perform();
y = link.getLocation().y;
// After scrolling, the location of the element should change accordingly.
assertTrue("Expected y < 3500, but got y = " + y, y < 3500);
}
项目:selendroid
文件:TouchScrollTest.java
@Test
public void testCanScrollHorizontallyFromWebElement() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link1"));
int x = link.getLocation().x;
// The element is located at the right of the page,
// so it is not initially visible on the screen.
assertTrue("Expected x > 1500, but got x = " + x, x > 1500);
WebElement toScroll = driver().findElement(By.id("imagestart"));
Action scroll = getBuilder(driver()).scroll(toScroll, -1000, 0).build();
scroll.perform();
x = link.getLocation().x;
// After scrolling, the location of the element should change accordingly.
assertTrue("Expected x < 3000, but got x = " + x, x < 3000);
}
项目:selendroid
文件:TouchScrollTest.java
@Test
public void testCanScrollVertically() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link3"));
int y = link.getLocation().y;
// The element is located at the right of the page,
// so it is not initially visible on the screen.
assertTrue(y > 4200);
Action scrollDown = getBuilder(driver()).scroll(0, 800).build();
scrollDown.perform();
y = link.getLocation().y;
// After scrolling, the location of the element should change accordingly.
assertTrue(y < 3500);
}
项目:selendroid
文件:TouchScrollTest.java
@Test
public void testCanScrollHorizontally() {
openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE);
WebElement link = driver().findElement(By.id("link1"));
int x = link.getLocation().x;
// The element is located at the right of the page,
// so it is not initially visible on the screen.
assertTrue("Expected x > 1500, but got x = " + x, x > 1500);
Action scrollDown = getBuilder(driver()).scroll(400, 0).build();
scrollDown.perform();
x = link.getLocation().y;
// After scrolling, the location of the element should change accordingly.
assertTrue("Expected x < 1500, but got x = " + x, x < 1500);
}
项目:OsBiToolsWs
文件:GenericPrjMgrGuiWebTest.java
public void dragDrop(WebElement from, WebElement to) {
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(from)
.moveToElement(to)
.release(to)
.build();
dragAndDrop.perform();
}
项目:webdrivermanager-examples
文件:CanvasTest.java
@Test
public void test() throws InterruptedException {
driver.get("http://szimek.github.io/signature_pad/");
WebElement canvas = driver.findElement(By.tagName("canvas"));
Action action = new Actions(driver).click(canvas)
.moveToElement(canvas, 8, 8).clickAndHold(canvas)
.moveByOffset(120, 120).moveByOffset(-120, 120)
.moveByOffset(-120, -120).moveByOffset(8, 8).release(canvas)
.build();
action.perform();
Thread.sleep(5000);
}
项目:OsBiToolsWs
文件:GenericPrjMgrGuiWebTest.java
public void dragDrop(WebElement from, WebElement to) {
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(from)
.moveToElement(to)
.release(to)
.build();
dragAndDrop.perform();
}
项目:atom
文件:AtomSeleniumTests.java
@Test() //dependsOnMethods = "displayListOf")
public void openFirstListElement() {
WebElement listRootPanel = waitTillElementContains("gwt-debug-listRootPanel", defaultTimeout, "Anzeige Eintrag");
if(countAfterListOpened > 0) {
// RootPanel/div tabindex=0 /div style pixel/div class XMOC /div class XG0B /div class XB-B /table cl. XNOC /tbody nr. 2 /tr/td/div
WebElement div = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*/*"));
// WebElement tr = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*"));
// WebElement td = listRootPanel.findElement(By.xpath("./*[position()=1]/*[position()=2]/*[position()=1]/*[position()=2]/*[position()=1]/*[position()=1]/*[position()=2]/*/*"));
Actions actions = new Actions(webDriver);
actions.doubleClick(div);
Action dblClick = actions.build();
dblClick.perform();
// Action dblClick = actions.doubleClick(div);
// dblClick.build().perform();
//
// actions.click(div);
// actions.click(div);
// actions.doubleClick(div);
// actions.doubleClick(td);
// actions.doubleClick(tr);
}
else
System.out.println("could not open element, since the list was empty!");
}
项目:gga-selenium-framework
文件:Element.java
/**
* A convenience method that performs click at the location of the source element
*
* @param xOffset - horizontal move offset.
* @param yOffset - vertical move offset.
* @return Parent instance
*/
public ParentPanel clickBy(int xOffset, int yOffset) {
doJAction(format("click element: horizontal move offset- %dpx; vertical move offset- %dpx", xOffset, yOffset), () -> {
Actions builder = new Actions(getDriver());
Action click = builder.moveToElement(getWebElement(), xOffset, yOffset).click().build();
click.perform();
});
return parent;
}
项目:wiselenium
文件:ComponentImpl.java
@SuppressWarnings("unchecked")
@Override
public T doubleClick() {
WebDriver driver = WiseContext.getDriver();
Action action = new Actions(driver).doubleClick(this.getWrappedElement()).build();
action.perform();
return (T) this;
}
项目:liferay-blade-samples
文件:BladeSampleFunctionalActionUtil.java
public static void customClick(WebDriver webDriver, WebElement webElement) {
Actions action = new Actions(webDriver);
Actions actionMoveTo = action.moveToElement(webElement);
Action buildActionMoveTo = actionMoveTo.build();
buildActionMoveTo.perform();
WebDriverWait wait = new WebDriverWait(webDriver, 30);
WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(webElement));
element.click();
}
项目:alimama
文件:SeleniumUtil.java
public static void dataokeLoginTest()throws Exception{
WebDriver driver = initChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.dataoke.com/login");
JavascriptExecutor js = (JavascriptExecutor) driver;
boolean flag = doesWebElementExist(driver, By.id("nc_1__scale_text"));
if(flag){
System.out.println("拖动存在>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//
Actions action = new Actions(driver);
//获取滑动滑块的标签元素
WebElement source = driver.findElement(By.id("nc_1__scale_text"));
//确保每次拖动的像素不同,故而使用随机数
//action.clickAndHold(source).moveByOffset(100, 0);
//Thread.sleep(1000);
//确保每次拖动的像素不同,故而使用随机数
//action.clickAndHold(source).moveByOffset(200, 0);
//Thread.sleep(1000);
//确保每次拖动的像素不同,故而使用随机数
action.clickAndHold(source).moveByOffset(300, 0);
Thread.sleep(1000);
//拖动完释放鼠标
action.moveToElement(source).release();
Thread.sleep(1000);
//组织完这些一系列的步骤,然后开始真实执行操作
Action actions = action.build();
actions.perform();
Thread.sleep(3000);
System.out.println("拖动完成>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
}
项目:product-iots
文件:ConnectedCupDeviceInterface.java
/**
* This method performs the slider change action of the web interface.
* @param slider : The element of the slider to be changed.
* @param val : Value to be set.
*/
private void moveSlider(WebElement slider, int val) {
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 0, val).build();
action.perform();
}
项目:powersweeper
文件:ScreenGameInterface.java
@Override
public ArrayList<Action> getActionQueue() {
return actionsQueue;
}
项目:selendroid
文件:TouchSingleTapTest.java
private void singleTapOnElement(String elementId) {
WebElement toSingleTap = driver().findElement(By.id(elementId));
Action singleTap = getBuilder(driver()).singleTap(toSingleTap).build();
singleTap.perform();
}
项目:powersweeper
文件:IGameInterface.java
/**
* Gets the action queue if it has one.
* @return Actions in an array list to cycle through.
*/
public ArrayList<Action> getActionQueue();