List of usage examples for org.openqa.selenium WebElement getSize
Dimension getSize();
From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java
License:Open Source License
/** * Visualy mark an element on the webPage. * * @param wd//from w w w . jav a2 s . c om * @param we * @param innerHtml - content of message dv * @param backrgba - background color string : try 'red' or * 'rgba(64,0,0,0.3)' * @param frontrgba - front color for border and text */ public static void highlightElement(WebDriver wd, WebElement we, String innerHtml, String backrgba, String frontrgba) { if (wd == null || we == null) { return; } // scrollElementIntoView(wd, we); // Get element size and location int left = we.getLocation().x; int top = we.getLocation().y; int width = we.getSize().width; int height = we.getSize().height; final String css = String.format("color:%s;" + "background-color:%s;" + "border-style:dashed;border-width:2px;border-color:%s; " + "position:absolute;" + "top:%dpx;left:%dpx;" + "width:%dpx;height:%dpx;" + "z-index:1000;", frontrgba, backrgba, frontrgba, top, left, width, height); final String script = String.format("elem = document.createElement('div');" + "elem.innerHTML='%s';" + "elem.setAttribute('style','%s');" + "document.body.appendChild(elem);", innerHtml, css); ((JavascriptExecutor) wd).executeScript(script); }
From source file:com.twiceagain.rservejavademo.extract.FTree.java
private void initFTree(WebDriver wd, WebElement we, FTree parent) { if (parent != null) { this.parent = parent; depth = parent.getDepth() + 1;/*from w w w .j av a 2s.c o m*/ path.addAll(parent.path); path.add(we.getTagName()); } if (we != null) { tag = we.getTagName(); visible = we.isDisplayed(); if (isVisible()) { Dimension d = we.getSize(); width = d.width; height = d.height; Point p = we.getLocation(); x = p.x; y = p.y; area = getWidth() * getHeight(); ratio = (getHeight() == 0) ? 0 : getWidth() / getHeight(); text = we.getText(); } attributes.putAll(BasicDriver.getAttributes(wd, we)); String cl = attributes.get("class"); if (cl != null) { classList.addAll(Arrays.asList(cl.split("\\s+"))); } List<WebElement> lwe = we.findElements(By.xpath("./*")); for (WebElement w : lwe) { FTree cc = new FTree(wd, w, this); getChildren().add(cc); } } }
From source file:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java
License:Open Source License
boolean isElementSelected(WebElement element) { updateSelectionLocationAndSize();//from w w w.ja v a2 s .co m Point location = element.getLocation(); location.x += element.getSize().getWidth() / 2; location.y += element.getSize().getHeight() / 2; return isInSelection(location) || isNonCoherentlySelected(element); }
From source file:com.vaadin.tests.components.calendar.CalendarMonthViewDndEventTest.java
License:Apache License
@Test public void dragAndDropEventToNextDay() { openTestURL();/*from w w w .ja v a 2 s . com*/ WebElement calendar = findElement(By.className("v-calendar")); int calendarRight = calendar.getLocation().getX() + calendar.getSize().getWidth(); WebElement event = findElement(By.className("v-calendar-event")); int x = event.getLocation().getX(); int width = event.getSize().getWidth(); // does calendar have space on the right for one more event (i.e. day // cell on the right). boolean moveRight = event.getLocation().getX() + 2 * event.getSize().getWidth() <= calendarRight; WebElement cell = getParentCell(event, "v-calendar-month-day"); int cellY = cell.getLocation().getY(); int cellHeight = cell.getSize().getHeight(); long origStart = getTime("start"); long origEnd = getTime("end"); if (moveRight) { dragAndDrop(event, event.getSize().getWidth() + 5, 0); } else { dragAndDrop(event, -width / 2, 0); } event = findElement(By.className("v-calendar-event")); int newX = event.getLocation().getX(); int newY = event.getLocation().getY(); Assert.assertTrue("Moved event has wrong Y position (not the same row), new Y position=" + newY + ", cell Y position=" + cellY + ", cell height=" + cellHeight, newY >= cellY && newY < cellY + cellHeight); if (moveRight) { Assert.assertTrue("Moved event has wrong X position (not after original event)", newX >= x + width - 1); } else { width = event.getSize().getWidth(); Assert.assertTrue("Moved event has wrong X position (not after original event)", x >= newX + width - 1); } long start = getTime("start"); long end = getTime("end"); int day = 24 * 3600000; if (moveRight) { Assert.assertEquals("Start date of moved event is not next day, same time", origStart + day, start); Assert.assertEquals("End date of moved event is not next day, same time", origEnd + day, end); } else { Assert.assertEquals("Start date of moved event is not previous day, same time", origStart - day, start); Assert.assertEquals("End date of moved event is not previous day, same time", origEnd - day, end); } }
From source file:com.vaadin.tests.components.calendar.CalendarNotificationsTestIE.java
License:Apache License
@Test public void notificationTest() throws Exception { openTestURL();//from w w w .j a v a 2 s . c om WebElement day = findElements(By.className("v-calendar-day-number")).get(2); // IE8 requires you to click on the text part to fire the event new Actions(getDriver()).moveToElement(day, day.getSize().getWidth() - 3, day.getSize().getHeight() / 2) .click().perform(); // check that a notification was opened, this is done with a log instead // of a screenshot or element presence check due to problems with IE // webdriver String text = findElement(By.id("Log")).findElement(By.className("v-label")).getText(); Assert.assertTrue("Notification should've opened", "1. Opening a notification".equals(text)); // move the mouse around a bit new Actions(getDriver()).moveByOffset(5, 5).moveByOffset(100, 100).perform(); // wait until the notification has animated out sleep(1000); Assert.assertFalse("There should be no notification on the page", $(NotificationElement.class).exists()); }
From source file:com.vaadin.tests.components.calendar.CalendarResizeOverlappingEventsTest.java
License:Apache License
private void initParams() { WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot")); int dateSlotWidth = dateSlot.getSize().getWidth(); noOverlapWidth = dateSlotWidth;/*from w ww . j a v a 2 s .co m*/ oneOverlapWidth = dateSlotWidth / 2; twoOverlapsWidth = dateSlotWidth / 3; Comparator<WebElement> startTimeComparator = new Comparator<WebElement>() { @Override public int compare(WebElement e1, WebElement e2) { int e1Top = e1.getLocation().getY(); int e2Top = e2.getLocation().getY(); return e1Top - e2Top; } }; List<WebElement> eventElements = getDriver().findElements(By.className("v-calendar-event-content")); Collections.sort(eventElements, startTimeComparator); firstEvent = eventElements.get(0); secondEvent = eventElements.get(1); thirdEvent = eventElements.get(2); List<WebElement> resizeBottomElements = getDriver() .findElements(By.className("v-calendar-event-resizebottom")); Collections.sort(resizeBottomElements, startTimeComparator); firstEventBottomResize = resizeBottomElements.get(0); secondEventBottomResize = resizeBottomElements.get(1); thirdEventBottomResize = resizeBottomElements.get(2); }
From source file:com.vaadin.tests.components.calendar.SetFirstVisibleHourOfDaySpecialCaseTest.java
License:Apache License
@Test public void testDayView() { openTestURL();//from ww w . jav a 2 s .c o m // open day view clickElement("v-calendar-day-number", "5"); // first of all check if event is present in calendar view waitForElementPresent(By.className("v-calendar-event-content")); // check that event has correct height WebElement event = getDriver().findElement(By.className("v-calendar-event-content")); WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot")); Assert.assertEquals("The height of shown part of calendar event should be equal to 16 datecell slots", dateSlot.getSize().getHeight() * 16, event.getSize().getHeight()); }
From source file:com.vaadin.tests.components.calendar.SetFirstVisibleHourOfDaySpecialCaseTest.java
License:Apache License
@Test public void testWeekView() { openTestURL();/*from www.java 2 s. com*/ // open week view clickElement("v-calendar-week-number", "36"); // first of all check if event is present in calendar view waitForElementPresent(By.className("v-calendar-event-content")); // check that event has correct height WebElement event = getDriver().findElement(By.className("v-calendar-event-content")); WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot")); Assert.assertEquals("The height of shown part of calendar event should be equal to 16 datecell slots", dateSlot.getSize().getHeight() * 16, event.getSize().getHeight()); }
From source file:com.vaadin.tests.components.calendar.SetFirstVisibleHourOfDaySpecialCaseTest.java
License:Apache License
private void clickElement(String className, String text) { List<WebElement> elements = findElements(By.className(className)); boolean found = false; for (WebElement webElement : elements) { if (webElement.getText().equals(text)) { webElement.click();//from w w w . ja v a 2 s .co m if (BrowserUtil.isIE8(getDesiredCapabilities())) { try { // sometimes the element only gets focus from click and // we need to click the text, which is in the right edge // of the element testBenchElement(webElement).click(webElement.getSize().getWidth() - 5, 9); } catch (StaleElementReferenceException e) { // the first click succeeded after all } } found = true; break; } } if (!found) { Assert.fail("Element " + className + " with text " + text + " not found."); } }
From source file:com.vaadin.tests.components.calendar.SetFirstVisibleHourOfDayTest.java
License:Apache License
@Test public void testDayView() { openTestURL();/*from w w w . j av a 2 s.c o m*/ waitForElementPresent(By.className("v-calendar")); // open day view clickElement("v-calendar-day-number", "5"); // first of all check if event is present in calendar view waitForElementPresent(By.className("v-calendar-event-content")); WebElement event = getDriver().findElement(By.className("v-calendar-event-content")); WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot")); Assert.assertEquals("The height of shown part of calendar event should be equal to 12 datecell slots", dateSlot.getSize().getHeight() * 12, event.getSize().getHeight()); }