Example usage for org.openqa.selenium.interactions Actions click

List of usage examples for org.openqa.selenium.interactions Actions click

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions click.

Prototype

public Actions click(WebElement target) 

Source Link

Document

Clicks in the middle of the given element.

Usage

From source file:org.richfaces.tests.showcase.contextMenu.AbstractContextMenuTest.java

License:Open Source License

protected void checkContextMenuRenderedAtCorrectPosition(WebElement target, WebElement contextMenuPopup,
        InvocationType type, ExpectedCondition<Boolean> conditionTargetIsFocused) {
    Actions builder = new Actions(GrapheneContext.getProxy());

    if (conditionTargetIsFocused != null) {
        target.click();//from   w w  w .  jav  a 2s.c o m
        Graphene.waitGui(webDriver).withTimeout(2, TimeUnit.SECONDS).until(conditionTargetIsFocused);
    }
    waitGui();

    // clicks in the middle of the target
    switch (type) {
    case LEFT_CLICK:
        builder.click(target);
        break;
    case RIGHT_CLICK:
        builder.contextClick(target);
        break;
    default:
        throw new IllegalArgumentException("Wrong type of context menu invocation!");
    }
    builder.build().perform();

    Graphene.waitGui().withTimeout(2, TimeUnit.SECONDS).until(element(contextMenuPopup).isVisible());

    Point locationOfTarget = target.getLocation();
    Point locationOfCtxMenu = contextMenuPopup.getLocation();

    double witdth = getTargetWidth(target);
    double height = getTargetHeight(target);

    double halfOfDiagonal = Math.sqrt((height * height) + (witdth * witdth)) / 2.0;
    double distance = getDistance(locationOfTarget, locationOfCtxMenu);

    double result = halfOfDiagonal - distance;

    assertTrue(result >= 0 && result < TOLERANCE,
            "The context menu was not rendered on the correct position! The difference is: " + result);
}

From source file:ru.stqa.selenium.wait.ClientSideImplicitWaitWrapperTest.java

License:Apache License

@Test
public void interactionsClickShouldImplicitlyWaitForTheElementToBeVisible() {
    final Keyboard mockedKeyboard = mock(Keyboard.class);
    final Mouse mockedMouse = mock(Mouse.class);

    final LocatableElement mockedElement = mock(LocatableElement.class);
    final Coordinates mockedCoords = mock(Coordinates.class);

    when(((HasInputDevices) mockedDriver).getKeyboard()).thenReturn(mockedKeyboard);
    when(((HasInputDevices) mockedDriver).getMouse()).thenReturn(mockedMouse);

    when(mockedDriver.findElement(By.name("foo"))).thenReturn(mockedElement);

    when(mockedElement.getCoordinates()).thenThrow(new ElementNotVisibleException("1"))
            .thenThrow(new ElementNotVisibleException("2")).thenReturn(mockedCoords);

    final Actions actions = new Actions(driver);
    WebElement element = driver.findElement(By.name("foo"));
    actions.click(element).perform();

    assertThat(clock.now(), is(200L));/*w w  w  .j  a va 2s.  co  m*/
    verify(mockedDriver, times(1)).findElement(By.name("foo"));
    verify(mockedElement, times(5)).getCoordinates(); // there are 2 extra calls
    verify(mockedMouse, times(1)).click((Coordinates) anyObject());
}

From source file:ru.stqa.selenium.wait.ImplicitlyWaitingWebDriverTest.java

License:Apache License

@Test
void interactionsClickShouldImplicitlyWaitForTheElementToBeVisible() {
    final Keyboard mockedKeyboard = mock(Keyboard.class);
    final Mouse mockedMouse = mock(Mouse.class);

    final LocatableElement mockedElement = mock(LocatableElement.class);
    final Coordinates mockedCoords = mock(Coordinates.class);

    when(((HasInputDevices) mockedDriver).getKeyboard()).thenReturn(mockedKeyboard);
    when(((HasInputDevices) mockedDriver).getMouse()).thenReturn(mockedMouse);

    when(mockedDriver.findElement(By.name("foo"))).thenReturn(mockedElement);

    when(mockedElement.getCoordinates()).thenThrow(new ElementNotVisibleException("1"))
            .thenThrow(new ElementNotVisibleException("2")).thenReturn(mockedCoords);

    final Actions actions = new Actions(driver);
    WebElement element = driver.findElement(By.name("foo"));
    actions.click(element).perform();

    assertThat(clock.now(), is(200L));/*from   w w  w  .  java 2  s .c o  m*/
    verify(mockedDriver, times(1)).findElement(By.name("foo"));
    verify(mockedElement, times(5)).getCoordinates(); // there are 2 extra calls
    verify(mockedMouse, times(1)).click((Coordinates) anyObject());
}