List of usage examples for org.openqa.selenium WebElement getLocation
Point getLocation();
From source file:io.selendroid.webviewdrivertests.touch.TouchFlickTest.java
License:Apache License
@Test public void testCanFlickVerticallyFastFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link4")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 8700);/*w w w . j ava2s.c o m*/ WebElement toFlick = driver().findElement(By.id("imagestart")); Action flick = getBuilder(driver()).flick(toFlick, 0, -600, FlickAction.SPEED_FAST).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Expected y < 8700, but got: " + y, y < 8700); }
From source file:io.selendroid.webviewdrivertests.touch.TouchFlickTest.java
License:Apache License
@Test public void testCanFlickVertically() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 4200);/*from www.j a va 2 s.c o m*/ Action flick = getBuilder(driver()).flick(0, 750).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Got: " + y, y < 4200); }
From source file:io.selendroid.webviewdrivertests.touch.TouchFlickTest.java
License:Apache License
@Test public void testCanFlickVerticallyFast() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link4")); int y = link.getLocation().y; // The element is located at the bottom of the page, // so it is not initially visible on the screen. assertTrue(y > 8700);//w w w. j av a2 s .co m Action flick = getBuilder(driver()).flick(0, 1500).build(); flick.perform(); y = link.getLocation().y; // After flicking, the element should now be visible on the screen. assertTrue("Got: " + y, y < 4000); }
From source file:io.selendroid.webviewdrivertests.touch.TouchScrollTest.java
License:Apache License
@Test public void testCanScrollVerticallyFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected y > 4200, but got y = " + y, y > 4200); WebElement toScroll = driver().findElement(By.id("imagestart")); Action scroll = getBuilder(driver()).scroll(toScroll, 0, -800).build(); scroll.perform();//from ww w.ja v a 2 s. c om y = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue("Expected y < 3500, but got y = " + y, y < 3500); }
From source file:io.selendroid.webviewdrivertests.touch.TouchScrollTest.java
License:Apache License
@Test public void testCanScrollHorizontallyFromWebElement() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link1")); int x = link.getLocation().x; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected x > 1500, but got x = " + x, x > 1500); WebElement toScroll = driver().findElement(By.id("imagestart")); Action scroll = getBuilder(driver()).scroll(toScroll, -1000, 0).build(); scroll.perform();//from w w w.j a va2s . c om x = link.getLocation().x; // After scrolling, the location of the element should change accordingly. assertTrue("Expected x < 3000, but got x = " + x, x < 3000); }
From source file:io.selendroid.webviewdrivertests.touch.TouchScrollTest.java
License:Apache License
@Test public void testCanScrollVertically() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link3")); int y = link.getLocation().y; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue(y > 4200);/*from w w w . ja v a2 s . c o m*/ Action scrollDown = getBuilder(driver()).scroll(0, 800).build(); scrollDown.perform(); y = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue(y < 3500); }
From source file:io.selendroid.webviewdrivertests.touch.TouchScrollTest.java
License:Apache License
@Test public void testCanScrollHorizontally() { openWebdriverTestPage(HtmlTestData.LONG_CONTENT_PAGE); WebElement link = driver().findElement(By.id("link1")); int x = link.getLocation().x; // The element is located at the right of the page, // so it is not initially visible on the screen. assertTrue("Expected x > 1500, but got x = " + x, x > 1500); Action scrollDown = getBuilder(driver()).scroll(400, 0).build(); scrollDown.perform();/*from w ww .j av a 2 s . c o m*/ x = link.getLocation().y; // After scrolling, the location of the element should change accordingly. assertTrue("Expected x < 1500, but got x = " + x, x < 1500); }
From source file:io.selendroid.webviewdrivertests.WebElementInteractionTest.java
License:Apache License
/** * Based on the default test emulator used to verify build that has a resolution of 320x480 * pixels./*from w ww.j av a 2 s. c o m*/ */ @Test public void shouldGetLocationOfElement() { givenWebViewWithFormPageLoaded(); WebElement element = driver().findElement(By.id("checky")); Point location = element.getLocation(); Assert.assertTrue(location.x >= 120); Assert.assertTrue(location.y >= 100); }
From source file:myfightinglayoutbugs.DetectElementsWithInvisibleFocus.java
License:Apache License
private FocusedElement toFocusedElement(@Nonnull WebElement activeElement, WebPage webPage) { // I don't trust WebDriver, that's why I determine the offset, width and height with jQuery too ... @SuppressWarnings("unchecked") Map<String, Object> temp = (Map<String, Object>) JsonHelper .parse((String) webPage .executeJavaScript(/* w w w . j av a 2s .c o m*/ "var $element = jQuery(arguments[0]);\n" + "var offset = $element.offset();\n" + "var $temp = $element.clone(false).wrap('<div></div>').parent();\n" + "try {\n" + " return JSON.stringify({\n" + " x: offset.left,\n" + " y: offset.top,\n" + " w: $element.width(),\n" + " h: $element.height(),\n" + " html: $temp.html()\n" + " });\n" + "} finally {\n" + " $temp.remove();\n" + "}", activeElement)); int x = ((Number) temp.get("x")).intValue(); int y = ((Number) temp.get("y")).intValue(); int w = ((Number) temp.get("w")).intValue(); int h = ((Number) temp.get("h")).intValue(); String html = (String) temp.get("html"); if (activeElement.isDisplayed()) { //Point location = //activeElement.getLocation().getX(); //Dimension size = activeElement.getSize().height; int x1 = Math.min(activeElement.getLocation().getX(), x); int y1 = Math.min(activeElement.getLocation().getY(), y); int x2 = Math.max(activeElement.getLocation().getX() + activeElement.getSize().getWidth(), x + w) - 1; int y2 = Math.max(activeElement.getLocation().getY() + activeElement.getSize().getHeight(), y + h) - 1; return new FocusedElement(activeElement, new RectangularRegion(x1, y1, x2, y2), html); } else { return new FocusedElement(activeElement, NOT_DISPLAYED, html); } }
From source file:net.codestory.simplelenium.filters.LazyShould.java
License:Apache License
private static boolean hasLocation(WebElement element, int x, int y) { Point location = element.getLocation(); return location.getX() == x && location.getY() == y; }