use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.
the class SuvianTest method test15_3.
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.interactions.Mouse
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.interactions.internal.Coordinates
// http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium/selenium-api/2.40.0/org/openqa/selenium/interactions/Mouse.java#Mouse.mouseMove%28org.openqa.selenium.interactions.internal.Coordinates%2Clong%2Clong%29
@Test(enabled = true)
public void test15_3() {
// Arrange
driver.get("http://suvian.in/selenium/2.5resize.html");
WebElement textAreaElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h3 textarea"))));
assertThat(textAreaElement, notNullValue());
System.err.println(textAreaElement.getSize().width);
System.err.println(textAreaElement.getSize().height);
WebElement lineElement = driver.findElement(By.cssSelector(".container .row .intro-message h3 hr.intro-divider"));
assertThat(lineElement, notNullValue());
// Act
int distance = (lineElement.getSize().width - textAreaElement.getSize().width) / 2;
highlight(textAreaElement);
int xOffset = textAreaElement.getSize().getWidth() - 1;
int yOffset = textAreaElement.getSize().getHeight() - 1;
Mouse mouse = ((HasInputDevices) driver).getMouse();
Locatable locatable = (Locatable) textAreaElement;
Coordinates coords = locatable.getCoordinates();
System.err.println(String.format("Mouse down at: (%d,%d)", coords.inViewPort().x, coords.inViewPort().y));
mouse.mouseMove(coords, xOffset, yOffset);
sleep(1000);
mouse.mouseDown(coords);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
mouse.mouseUp(coords);
mouse.click(coords);
sleep(1000);
}
use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.
the class SuvianTest method test15_2.
@Test(enabled = true)
public void test15_2() {
// Arrange
driver.get("http://suvian.in/selenium/1.1link.html");
String cssSelector = ".container .row .intro-message h3 a";
WebElement element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h3 a"))));
assertTrue(element.getText().equalsIgnoreCase("click here"), element.getText());
// Act
highlight(element);
Mouse mouse = ((HasInputDevices) driver).getMouse();
Coordinates coords = ((Locatable) element).getCoordinates();
System.err.println(String.format("Mouse click at: (%-4d, %-4d)", coords.inViewPort().x, coords.inViewPort().y));
mouse.click(coords);
// Wait page to load
try {
wait.until(ExpectedConditions.urlContains("1.1link_validate.html"));
} catch (UnreachableBrowserException e) {
}
// Assert
try {
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
return d.findElement(By.className("intro-message")).getText().contains("Link Successfully clicked");
}
});
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
}
use of org.openqa.selenium.internal.Locatable in project carina by qaprosoft.
the class ExtendedWebElement method scrollTo.
/**
* Scroll to element (applied only for desktop).
*/
@Deprecated
public void scrollTo() {
if (Configuration.getDriverType().equals(SpecialKeywords.MOBILE)) {
LOGGER.debug("scrollTo javascript is unsupported for mobile devices!");
return;
}
try {
Locatable locatableElement = (Locatable) findElement(EXPLICIT_TIMEOUT);
// [VD] onScreen should be updated onto onPage as only 2nd one
// returns real coordinates without scrolling... read below material
// for details
// https://groups.google.com/d/msg/selenium-developers/nJR5VnL-3Qs/uqUkXFw4FSwJ
// [CB] onPage -> inViewPort
// https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java?r=abc64b1df10d5f5d72d11fba37fabf5e85644081
int y = locatableElement.getCoordinates().inViewPort().getY();
int offset = R.CONFIG.getInt("scroll_to_element_y_offset");
((JavascriptExecutor) getDriver()).executeScript("window.scrollBy(0," + (y - offset) + ");");
} catch (Exception e) {
// TODO: calm error logging as it is too noisy
// LOGGER.debug("Scroll to element: " + getName() + " not
// performed!" + e.getMessage());
}
}
use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.
the class SuvianTest method test20_4.
// Attempt #4
@Test(enabled = true)
public void test20_4() {
// Arrange
driver.get("http://suvian.in/selenium/2.10dragAndDrop.html");
WebElement draggableElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h5#drag1 strong"))));
assertThat(draggableElement, notNullValue());
assertThat(draggableElement.getText(), containsString("This is a draggable text."));
WebElement dropElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='div1']"))));
assertThat(dropElement, notNullValue());
assertThat(dropElement.getText(), containsString("Drop Here"));
// Act
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_coords.inViewPort().y - source_coords.inViewPort().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);
sleep(1000);
System.err.println("Result: " + dropElement.getAttribute("innerHTML"));
// Assert
}
use of org.openqa.selenium.internal.Locatable in project selenium_java by sergueik.
the class SuvianTest method test20_5.
// Attempt #5
@Test(enabled = true)
public void test20_5() {
// Arrange
driver.get("http://suvian.in/selenium/2.10dragAndDrop.html");
WebElement draggableElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h5#drag1 strong"))));
assertThat(draggableElement, notNullValue());
assertThat(draggableElement.getText(), containsString("This is a draggable text."));
WebElement dropElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='div1']"))));
assertThat(dropElement, notNullValue());
assertThat(dropElement.getText(), containsString("Drop Here"));
// Act
Coordinates source_coords = ((Locatable) draggableElement).getCoordinates();
Coordinates target_coords = ((Locatable) dropElement).getCoordinates();
String simulateDragDropScript = getScriptContent("simulateDragDrop.js");
System.err.println(String.format("Simulate drag an drop by: (%-4d, %-4d)", target_coords.inViewPort().x, target_coords.inViewPort().y));
executeScript(simulateDragDropScript, draggableElement, target_coords.inViewPort().x, target_coords.inViewPort().y);
sleep(1000);
System.err.println("Result: " + dropElement.getAttribute("innerHTML"));
// Assert
}
Aggregations