Search in sources :

Example 6 with Locatable

use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.

the class SuvianTest method test22_4.

// Few failing attempts. Warning: Timing out with Firefox
@Test(enabled = true)
public void test22_4() {
    // Arrange
    driver.get("http://suvian.in/selenium/3.2dragAndDrop.html");
    WebElement draggableElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("drag1"))));
    assertThat(draggableElement, notNullValue());
    assertThat(draggableElement.getAttribute("src"), containsString("img/img_logo.gif"));
    WebElement dropElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='div1']"))));
    assertThat(dropElement, notNullValue());
    // Attempt #3
    Point source_location = draggableElement.getLocation();
    highlight(draggableElement);
    Point target_location = dropElement.getLocation();
    actions.dragAndDropBy(draggableElement, 0, target_location.y - source_location.y).build().perform();
    actions.release().build();
    actions.perform();
    // Attempt #4
    Mouse mouse = ((HasInputDevices) driver).getMouse();
    Coordinates source_coords = ((Locatable) draggableElement).getCoordinates();
    Coordinates target_coords = ((Locatable) dropElement).getCoordinates();
    System.err.println(String.format("Mouse down at: (%-4d, %-4d)", source_coords.inViewPort().x, source_coords.inViewPort().y));
    mouse.mouseDown(source_coords);
    mouse.mouseMove(source_coords, 0, target_location.y - source_location.y);
    System.err.println(String.format("Mouse up at: (%-4d, %-4d)", target_coords.inViewPort().x + 10, target_coords.inViewPort().y + 10));
    mouse.mouseUp(target_coords);
// Assert
}
Also used : Mouse(org.openqa.selenium.interactions.Mouse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) Point(org.openqa.selenium.Point) WebElement(org.openqa.selenium.WebElement) Locatable(org.openqa.selenium.internal.Locatable) Test(org.testng.annotations.Test)

Example 7 with Locatable

use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.

the class BaseTest method scrolltoElement.

// origin:
// https://github.com/TsvetomirSlavov/JavaScriptForSeleniumMyCollection/blob/master/src/utils/UtilsQAAutoman.java
public void scrolltoElement(WebElement element) {
    Coordinates coordinate = ((Locatable) element).getCoordinates();
    coordinate.onPage();
    coordinate.inViewPort();
}
Also used : Coordinates(org.openqa.selenium.interactions.internal.Coordinates) Locatable(org.openqa.selenium.internal.Locatable)

Aggregations

Locatable (org.openqa.selenium.internal.Locatable)7 Coordinates (org.openqa.selenium.interactions.internal.Coordinates)6 WebElement (org.openqa.selenium.WebElement)5 Test (org.testng.annotations.Test)5 HasInputDevices (org.openqa.selenium.interactions.HasInputDevices)4 Mouse (org.openqa.selenium.interactions.Mouse)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Point (org.openqa.selenium.Point)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidSelectorException (org.openqa.selenium.InvalidSelectorException)1 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)1 WebDriver (org.openqa.selenium.WebDriver)1 WebDriverException (org.openqa.selenium.WebDriverException)1 UnreachableBrowserException (org.openqa.selenium.remote.UnreachableBrowserException)1