當前位置: 首頁>>代碼示例>>Java>>正文


Java Actions類代碼示例

本文整理匯總了Java中org.openqa.selenium.interactions.Actions的典型用法代碼示例。如果您正苦於以下問題:Java Actions類的具體用法?Java Actions怎麽用?Java Actions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Actions類屬於org.openqa.selenium.interactions包,在下文中一共展示了Actions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: click

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void click() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)"));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:JavaDriverTest.java

示例2: draggedGeneratesSameEvents

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void draggedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_DRAGGED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");

    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    tclear();
    System.err.println("============================");
    new Actions(driver).clickAndHold(b).moveToElement(b).release().perform();
    System.err.println("============================");
    AssertJUnit.assertEquals(expected, t.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:41,代碼來源:NativeEventsTest.java

示例3: clickAddStepLink

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void clickAddStepLink(int pos){

		List<WebElement> allStepInserts = getRootElement().findElements(Element.STEP_INSERT);
		WebElement stepElement = allStepInserts.get(pos);
		Actions action = new Actions(WebDriverRunner.getWebDriver());
		//to make ADD_STEP element visible:
		action.moveToElement(stepElement);

		getRootElement().$(Link.ADD_STEP).shouldBe(visible).click();
	}
 
開發者ID:syndesisio,項目名稱:syndesis-qe,代碼行數:11,代碼來源:IntegrationFlowViewComponent.java

示例4: dragAndDropTo

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:25,代碼來源:HiddenHtmlElement.java

示例5: scrollGameIntoView

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
private void scrollGameIntoView() {
	/*
	 * Bellow code doesn't work well (it does not scroll horizontally):
	 * 
	 * ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", game);
	 */
	Actions actions = new Actions(driver);
	actions.moveToElement(game);
	actions.perform();
}
 
開發者ID:Betalord,項目名稱:BHBot,代碼行數:11,代碼來源:MainThread.java

示例6: homePageShouldWork

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	driver.navigate().back();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:EndToEndTests.java

示例7: homePageShouldWork

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	takeScreenshot("homePageShouldWork-1");

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	takeScreenshot("homePageShouldWork-2");

	driver.navigate().back();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:24,代碼來源:EndToEndTests.java

示例8: checkAltRightClickEvent

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
private void checkAltRightClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).keyDown(Keys.ALT).contextClick().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
    // Wait till the previous click is processed by the EDT
    Thread.sleep(500);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:40,代碼來源:NativeEventsTest.java

示例9: checkDoubleClickEvent

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
private void checkDoubleClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().contains("(2");
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).doubleClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:39,代碼來源:NativeEventsTest.java

示例10: enteredGeneratesSameEvents

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:39,代碼來源:NativeEventsTest.java

示例11: releaseGeneratesSameEvents

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void releaseGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_RELEASED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:41,代碼來源:NativeEventsTest.java

示例12: expandTree

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void expandTree() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("false", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(root, "expanded", "true"));
    AssertJUnit.assertEquals("true", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    new Actions(driver).doubleClick(node1).perform();
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Child 1", node2.getText());
    WebElement node3 = tree.findElement(By.cssSelector(".::nth-node(4)"));
    AssertJUnit.assertEquals("Child 2", node3.getText());
    WebElement node4 = tree.findElement(By.cssSelector(".::nth-node(5)"));
    AssertJUnit.assertEquals("Parent 2", node4.getText());
    new Actions(driver).doubleClick(node4).perform();
    WebElement node5 = tree.findElement(By.cssSelector(".::nth-node(6)"));
    AssertJUnit.assertEquals("Child 1", node5.getText());
    WebElement node6 = tree.findElement(By.cssSelector(".::nth-node(7)"));
    AssertJUnit.assertEquals("Child 2", node6.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:26,代碼來源:JTreeDynamicTreeTest.java

示例13: moveTo

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
@Test(enabled = false) public void moveTo() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    new Actions(driver).moveToElement(element1).click().perform();
    buttonMouseActions.setLength(0);
    new Actions(driver).moveToElement(element1).perform();
    AssertJUnit.assertTrue(buttonMouseActions.length() > 0);
    AssertJUnit.assertEquals("moved-", buttonMouseActions.toString());
    new Actions(driver).moveToElement(element1, 10, 10).perform();
    AssertJUnit.assertEquals("moved-moved-", buttonMouseActions.toString());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:18,代碼來源:JavaDriverTest.java

示例14: keysWithNativeEvents

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void keysWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            textField.requestFocusInWindow();
        }
    });
    AssertJUnit.assertEquals("", EventQueueWait.call(textField, "getText"));
    WebElement element1 = driver.findElement(By.name("text-field"));
    new Actions(driver).sendKeys(element1, "Hello World").perform();
    AssertJUnit.assertEquals("Hello World", EventQueueWait.call(textField, "getText"));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:17,代碼來源:JavaDriverTest.java

示例15: clickWithNativeEvents

import org.openqa.selenium.interactions.Actions; //導入依賴的package包/類
public void clickWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(new JavaProfile(), caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)")
            || buttonMouseActions.toString().contains("released(3-popup)"));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:JavaDriverTest.java


注:本文中的org.openqa.selenium.interactions.Actions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。