Java 类org.openqa.selenium.interactions.Actions 实例源码

项目:marathonv5    文件:JavaDriverTest.java   
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)"));
}
项目:marathonv5    文件:NativeEventsTest.java   
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());
}
项目: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();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:EndToEndTests.java   
@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();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:EndToEndTests.java   
@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();
}
项目:marathonv5    文件:NativeEventsTest.java   
private void checkAltClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    tclear();
    Point locationButton = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension sizeButton = EventQueueWait.call_noexc(button, "getSize");
    Point locationTextArea = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension sizeTextArea = EventQueueWait.call_noexc(actionsArea, "getSize");

    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(locationButton.x + sizeButton.width / 2 + 1, locationButton.y + sizeButton.height / 2 + 1);
    robot.mouseMove(locationButton.x + sizeButton.width / 2, locationButton.y + sizeButton.height / 2);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = weTextArea.getText();
    tclear();
    System.err.println("================================");
    System.err.println(expected);
    System.err.println("=================================");
    new Actions(driver).moveToElement(weButton).keyDown(Keys.ALT).click().keyUp(Keys.ALT).moveToElement(weTextArea).perform();
    AssertJUnit.assertEquals(expected, weTextArea.getText());
}
项目:marathonv5    文件:NativeEventsTest.java   
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);
}
项目:marathonv5    文件:NativeEventsTest.java   
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());
}
项目:marathonv5    文件:NativeEventsTest.java   
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());

}
项目:marathonv5    文件:NativeEventsTest.java   
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());

}
项目:marathonv5    文件:NativeEventsTest.java   
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    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.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_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);

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

}
项目:marathonv5    文件:JTreeDynamicTreeTest.java   
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());
}
项目:marathonv5    文件:JavaDriverTest.java   
@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());
}
项目:marathonv5    文件:JavaDriverTest.java   
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"));
}
项目:marathonv5    文件:JavaDriverTest.java   
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)"));
}
项目:marathonv5    文件:DragAndDropTest.java   
public void dndWithMove() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    driver.clearlogs(LogType.DRIVER);
    System.err.println("About to sleep");
    new Actions(driver).dragAndDrop(listitem1, listitem5).perform();
    waitTillDropCompletes(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
项目:marathonv5    文件:DragAndDropTest.java   
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
项目:Cognizant-Intelligent-Test-Scripter    文件:CommonMethods.java   
@Action(object = ObjectType.SELENIUM, desc = "Drad and drop the element [<Object>] at location [<Data>]", input = InputType.YES)
public void dragAndDropBy() {
    try {
        if (elementPresent()) {
            String[] coords = Data.split(",", 2);
            new Actions(Driver).dragAndDropBy(Element, Integer.parseInt(coords[0]), Integer.parseInt(coords[1]))
                    .build().perform();
            Report.updateTestLog(Action, "Element [" + ObjectName + "] dropped at '"
                    + Data + "' ", Status.PASS);

        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
        }
    } catch (Exception e) {
        Report.updateTestLog(Action, e.getMessage(), Status.DEBUG);
        Logger.getLogger(CommonMethods.class.getName()).log(Level.SEVERE, null, e);
    }

}
项目:Cognizant-Intelligent-Test-Scripter    文件:CommonMethods.java   
@Action(object = ObjectType.SELENIUM, desc = "Drops the Dragged Object to [<Object>]")
public void dropElement() {
    if (elementPresent()) {
        if (!getRunTimeElement().empty()) {
            new Actions(Driver)
                    .dragAndDrop(getRunTimeElement().pop(), Element)
                    .build().perform();
            Report.updateTestLog(Action, "Element  dropped to '"
                    + ObjectName + "' ", Status.DONE);
        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, "Drop Target");
        }
    } else {
        throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
    }
}
项目:marathonv5    文件:JMenuTest.java   
public void checkBoxMenuItemClick() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));
    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("check-box-menu-item"));
    int i = menuItems.size();
    assertMenuItemClick(menuItems, --i,
            "Event source: Another one (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    WebElement currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));

    new Actions(driver).moveToElement(menu).click().perform();
    assertMenuItemClick(menuItems, --i,
            "Event source: A check box menu item (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));
}
项目:marathonv5    文件:JMenuTest.java   
public void subMenu() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));

    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("menu"));
    int i = 2;
    assertMenuItem(menuItems, i++, "A submenu", "", "83");

    /*
     * NOTE: Clicking on the menu again to ensure that MenuManager sets the
     * state of this menu to closed. Without this call the state of the menu
     * remains open and this test or the next test which clicks on the same
     * menu and perform any actions or request attributes will fail. This
     * behavior is noticed on OSX
     */
    new Actions(driver).moveToElement(menu).click().perform();
}
项目:syndesis-qe    文件:IntegrationFlowViewComponent.java   
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();
    }
项目:Cognizant-Intelligent-Test-Scripter    文件:Basic.java   
@Action(object = ObjectType.SELENIUM,
        desc = "Move the Browser View to the specified element [<Object>]")
public void moveTo() {
    if (elementDisplayed()) {
        if (Data != null && Data.matches("(\\d)+,(\\d)+")) {
            int x = Integer.valueOf(Data.split(",")[0]);
            int y = Integer.valueOf(Data.split(",")[1]);
            new Actions(Driver).moveToElement(Element, x, y).build().perform();
        } else {
            new Actions(Driver).moveToElement(Element).build().perform();
        }
        Report.updateTestLog(Action, "Viewport moved to" + ObjectName, Status.DONE);
    } else {
        throw new ElementException(ExceptionType.Element_Not_Visible, ObjectName);
    }
}
项目:ats-framework    文件:MobileCheckBox.java   
/**
 * Check the check box
 */
@Override
@PublicAtsApi
public void check() {

    new MobileElementState(this).waitToBecomeExisting();

    try {
        WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
        if (!checkboxElement.isSelected()) {
            if (appiumDriver instanceof AndroidDriver) {

                // checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
                new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
            } else {

                checkboxElement.click();
            }
        }
    } catch (Exception se) {
        throw new MobileOperationException(this, "check", se);
    }

    UiEngineUtilities.sleep();
}
项目:ats-framework    文件:MobileCheckBox.java   
/**
 * Uncheck the check box
 */
@Override
@PublicAtsApi
public void unCheck() {

    new MobileElementState(this).waitToBecomeExisting();

    try {
        WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
        if (checkboxElement.isSelected()) {
            if (appiumDriver instanceof AndroidDriver) {

                // checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
                new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
            } else {

                checkboxElement.click();
            }
        }
    } catch (Exception se) {
        throw new MobileOperationException(this, "unCheck", se);
    }

    UiEngineUtilities.sleep();
}
项目:SWET    文件:SwetTest.java   
@BeforeClass
public static void beforeSuiteMethod() throws Exception {

    // browser selection is hard-coded

    System.err.println("os: " + osName);
    if (osName.startsWith("windows")) {
        driver = BrowserDriver.initialize(browser);
    } else if (osName.startsWith("mac")) {
        driver = BrowserDriver.initialize("safari");
    } else {
        driver = BrowserDriver.initialize("firefox");
    }
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
项目: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();
}
项目:hippo    文件:GranularityCmsWidget.java   
public void addGranularityField() {
    // get element
    WebElement addButton = helper.findElement(By.xpath(ROOT_ELEMENT_XPATH + "//a[contains(@class, 'add-link')]"));

    // scroll to element, to preven errors like "Other element would receive the click"
    new Actions(webDriver)
        .moveToElement(addButton)
        .moveByOffset(0, 200)
        .perform();

    // click
    addButton.click();

    // wait after click for the dropdown to appear
    helper.findElement(By.xpath(DROPDOWN_XPATH));
}
项目:hippo    文件:InformationTypeCmsWidget.java   
public void addInformationTypeField() {
    // get element
    WebElement addButton = helper.findElement(By.xpath(ROOT_ELEMENT_XPATH + "//a[contains(@class, 'add-link')]"));

    // scroll to element, to prevent errors like "Other element would receive the click"
    new Actions(webDriver)
        .moveToElement(addButton)
        .moveByOffset(0, 200)
        .perform();

    // click
    addButton.click();

    // wait after click for the dropdown to appear
    helper.findElement(By.xpath(DROPDOWN_XPATH));
}
项目:Cognizant-Intelligent-Test-Scripter    文件:CommonMethods.java   
@Action(object = ObjectType.SELENIUM, desc = "drag and drop operation of ", input = InputType.YES)
public void dragToAndDropElement() {
    try {
        String Page = Data.split(":", 2)[0];
        String Object = Data.split(":", 2)[1];
        if (elementPresent()) {
            WebElement DropElement = AObject.findElement(Object, Page);
            if (DropElement != null) {
                new Actions(Driver).dragAndDrop(Element, DropElement)
                        .build().perform();
                Report.updateTestLog(Action, "'" + ObjectName
                        + "' has been dragged and dropped to '" + Object + "'",
                        Status.PASS);
            } else {
                throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Object);
            }
        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
        }
    } catch (Exception e) {
        Report.updateTestLog(Action, e.getMessage(), Status.FAIL);
        Logger.getLogger(CommonMethods.class.getName()).log(Level.SEVERE, e.getMessage(), e);
    }
}
项目:teasy    文件:BaseTeasyElement.java   
private void clickForIgnoredScroll(WebDriverException ignoredOrNeedToScroll) {
    new Report("*****WebDriverException***** during click!-----Locator=" + locator.getBy()).jenkins();
    increment();
    //For Android error text is different and does not have any information related to clickable issue
    String ignoredOrNeedToScrollMessage = ignoredOrNeedToScroll.getMessage();
    if (ignoredOrNeedToScrollMessage.contains("is not clickable at point")) {
        new Report("*****Element is not clickable at point***** during click! Scrolling to element and trying again. ---Locator=" + locator.getBy()).jenkins();

        //This was added to fix cases when scrolling does not affect (in chrome when element is half hidden)
        //There is a chance that maximising will solve the case
        if (repeatLocateElementCounter == 10) {
            maximizeWindow();
            if (isChrome()) {
                //Some pages (e.g. in Administration Workspace) are reloaded after maximize window in Chrome
                waitForSomeTime(3000, "Wait for window maximized");
                againLocate();
            }
        }

        scrollIntoView(wrappedElement);
        scrollToElementLocation(wrappedElement);
    }
    if (ignoredOrNeedToScrollMessage.contains("Error: element is not attached to the page document")) {
        againLocate();
    }
    if (ignoredOrNeedToScrollMessage.contains("unknown error: no element reference returned by script")) {
        againLocate();
        executeScript("arguments[0].click();", wrappedElement);
    } else if (ignoredOrNeedToScrollMessage.contains("Other element would receive the click")) {
        //TODO NT: workaround for 2.49.1
        //If dropdown option element have bigger size then dropdown we get error 'Element is not clickable at point... Other element would receive the click...'
        Actions actions = new Actions(getWebDriver());
        actions
                .moveToElement(wrappedElement, 0, 0)
                .click()
                .perform();
    } else {
        click();
    }
}
项目:teasy    文件:AbstractPageElement.java   
@Deprecated
protected void hoverOverElement(WebElement webElement) {
    maximizeWindow();
    Actions builder = new Actions(getDriver());
    Actions hoverOverWebElement = builder.moveToElement(webElement);
    hoverOverWebElement.perform();
}
项目:akita    文件:DefaultSteps.java   
/**
 * Выполняется переход в конец страницы
 */
("^совершен переход в конец страницы$")
public void scrollDown() {
    Actions actions = new Actions(getWebDriver());
    actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).build().perform();
    actions.keyUp(Keys.CONTROL).perform();
}
项目:POM_HYBRID_FRAMEOWRK    文件:MouseOperations.java   
public static void hoverMouseOnWebElement(WebDriver driver, ExtentTest logger, WebElement element) {
    try {
        Actions action = new Actions(driver);
        action.moveToElement(element).build().perform();
    } catch (Exception e) {
        logger.log(LogStatus.ERROR, "Error hovering over the element</br>" + e.getCause());
    }
}
项目:phoenix.webui.framework    文件:SeleniumKeyBoard.java   
@Override
public void enter(Element element)
{
    WebDriver driver = engine.getDriver();

    new Actions(driver).keyDown(Keys.ENTER).perform();
}
项目:marathonv5    文件:JScrollBarTest.java   
public void getAttributes() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> scrollBars = driver.findElements(By.cssSelector("scroll-bar"));
    WebElement scrollbar = scrollBars.get(0);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(0, 40).click().perform();
    int scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 100);

    scrollbar = scrollBars.get(1);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(80, 0).click().perform();
    scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 10);
}
项目:marathonv5    文件:NativeEventsTest.java   
public void exitedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_EXITED;
    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);
    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);
    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();
    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).moveToElement(t).keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
项目:marathonv5    文件:NativeEventsTest.java   
private void checkKeyEvent(int eventToCheck, String keysToSend, int... keysToPress)
        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("enter-text"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(textField, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(textField, "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);
    for (int keysToPres : keysToPress) {
        r.keyPress(keysToPres);
    }
    for (int i = keysToPress.length - 1; i >= 0; i--) {
        r.keyRelease(keysToPress[i]);
    }
    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.sendKeys(keysToSend);
    System.out.println("Expected: " + expected);
    AssertJUnit.assertEquals(expected, t.getText());

    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
项目:marathonv5    文件:JSliderTest.java   
public void getAttributes() throws Throwable {
    driver = new JavaDriver();
    WebElement slider = driver.findElement(By.cssSelector("slider"));
    AssertJUnit.assertEquals("15", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_RIGHT);
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_LEFT);
    AssertJUnit.assertEquals("15", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_UP);
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_DOWN);
    }
    AssertJUnit.assertEquals("1", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_UP);
    }
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_LEFT);
    }
    AssertJUnit.assertEquals("1", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_RIGHT);
    }
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    new Actions(driver).moveToElement(slider).moveByOffset(40, 0).click().perform();
    int sliderValue = Integer.parseInt(slider.getAttribute("value"));
    AssertJUnit.assertTrue(sliderValue > 16);

}
项目:marathonv5    文件:JTreeDynamicTreeTest.java   
public void expandANode() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(tree, "rowCount", 3 + ""));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
}