List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:org.alfresco.po.common.util.Utils.java
License:Open Source License
/** * Helper to mouse over element/*from w w w . j av a2 s . c om*/ * * @param webElement * @return */ public static <T extends WebElement> T mouseOver(T webElement) { Actions actions = new Actions(getWebDriver()); actions.moveToElement(webElement).perform(); return webElement; }
From source file:org.alfresco.po.share.CustomiseUserDashboardPage.java
License:Open Source License
/** * Add given dashlet into given column.// ww w .j a va 2 s . c om * * @param dashletName Dashlets * @param columnNumber int * @return {@link SiteDashboardPage} */ public DashBoardPage addDashlet(Dashlets dashletName, int columnNumber) { if (dashletName == null) { throw new IllegalArgumentException("Dashlet Name is required"); } if (columnNumber < 1 || columnNumber > NUMBER_OF_COLUMNS) { throw new IllegalArgumentException("Column number should be between 1 and 4"); } WebElement newDashlet = null; int noOfColumns = 0; this.selectAddDashlets(); try { // String dashletXpath = String.format("//li[@class='availableDashlet dnd-draggable']/span[text()=\"%s\"]", dashletName.getDashletName()); // WebElement element = findAndWait(By.xpath(dashletXpath)); // executeJavaScript(String.format("window.scrollTo('%s', '%s')", element.getLocation().getX(), element.getLocation().getY())); String dashletSelector = String.format("li.availableDashlet div.dnd-draggable[title*=\"%s\"]", dashletName.getDashletName().replace("'", "\'")); By dashlet = By.cssSelector("li.availableDashlet div.dnd-draggable[title*=\"" + dashletName.getDashletName().replace("'", "\'") + "\"]"); WebElement element = findAndWait(dashlet); // Move element into View if not already Actions actions = new Actions(driver); actions.moveToElement(element).perform(); Coordinates coord = ((Locatable) element).getCoordinates(); coord.inViewPort(); element.click(); List<WebElement> dashlets = findAndWaitForElements(AVAILABLE_DASHLETS_NAMES, getDefaultWaitTime()); for (WebElement source : dashlets) { if (source.getText().equals(dashletName.getDashletName())) { newDashlet = source; break; } } } catch (TimeoutException te) { logger.error("Exceeded time to find the Available dashlet names ", te); } if (newDashlet != null) { try { String columns = driver.findElement(By.cssSelector("div[id$='default-wrapper-div']")) .getAttribute("class"); if (!StringUtils.isEmpty(columns)) { String columnSize = columns.substring(columns.length() - 1); noOfColumns = Integer.valueOf(columnSize); } } catch (NoSuchElementException te) { logger.error("Unable to find the Columns css " + te); } if (columnNumber <= noOfColumns) { try { List<WebElement> existingDashletsInColumn = Collections.emptyList(); try { existingDashletsInColumn = findAndWaitForElements( By.cssSelector(String.format("ul[id$='column-ul-%d'] li", columnNumber)), getDefaultWaitTime()); } catch (TimeoutException e) { logger.error("Selected column is empty", e); } if (existingDashletsInColumn.size() < MAX_DASHLETS_IN_COLUMN) { WebElement target = findAndWait(By.xpath(String.format( "//ul[@class='usedList' and contains(@id,'-column-ul-%d')]", columnNumber))); executeJavaScript(String.format("window.scrollTo(0, '%s')", target.getLocation().getY())); dragAndDrop(newDashlet, target); return selectOk(); } else { throw new PageOperationException("Exceeded the no. of dashlets in given column."); } } catch (TimeoutException te) { logger.error("Exceeded time to find the Available dashlet names ", te); } } else { throw new PageOperationException("Expected column does not exist in available columns list."); } } throw new PageOperationException("Error in adding dashlet using drag and drop"); }
From source file:org.alfresco.po.share.dashlet.AbstractDashlet.java
License:Open Source License
/** * This method is used to scroll down the current window. *///from ww w .j a v a 2 s .c o m protected void scrollDownToDashlet() { ; Actions a = new Actions(driver); a.moveToElement(driver.findElement(resizeHandle)); a.perform(); }
From source file:org.alfresco.po.share.dashlet.MyTasksDashlet.java
License:Open Source License
/** * Clicks on edit task for single task//from ww w .j a v a2 s .com * @param taskName String * @return {@link HtmlPage} */ public HtmlPage selectEditTask(String taskName) { if (taskName == null) { throw new UnsupportedOperationException("Taskname should not be null"); } try { List<WebElement> elements = driver.findElements(By.cssSelector(LIST_OF_TASKS)); for (WebElement webElement : elements) { if (webElement.getText().equals(taskName)) { Actions mouseOver = new Actions(driver); mouseOver.moveToElement(driver.findElement(By.xpath("//a[text()='" + taskName + "']"))) .moveToElement(driver.findElement( By.xpath("//h3/a[text()='" + taskName + "']/../../../..//" + TASK_EDIT_LINK))) .click().perform(); return getCurrentPage(); } } } catch (NoSuchElementException ex) { logger.error("My Task Dashlet is not present", ex); } throw new PageException("Task is not found"); }
From source file:org.alfresco.po.share.dashlet.MyTasksDashlet.java
License:Open Source License
/** * Clicks on edit task for single task//from w w w . java2 s .co m * @param taskName String * @return {@link HtmlPage} */ public HtmlPage selectViewTask(String taskName) { if (taskName == null) { throw new UnsupportedOperationException("Taskname should not be null"); } try { List<WebElement> elements = driver.findElements(By.cssSelector(LIST_OF_TASKS)); for (WebElement webElement : elements) { if (webElement.getText().equals(taskName)) { Actions mouseOver = new Actions(driver); mouseOver.moveToElement(driver.findElement(By.xpath("//a[text()='" + taskName + "']"))) .moveToElement(driver.findElement( By.xpath("//h3/a[text()='" + taskName + "']/../../../..//" + TASK_VIEW_LINK))) .click().perform(); return getCurrentPage(); } } } catch (NoSuchElementException ex) { logger.error("My Task Dashlet is not present", ex); } throw new PageException("Task is not found"); }
From source file:org.alfresco.po.share.MyTasksPage.java
License:Open Source License
/** * @param taskName String//from w ww . j a v a2s .co m * @param action By */ private void performActionOnTask(String taskName, By action) { if (taskName == null || action == null) { throw new UnsupportedOperationException("Both taskname and action should not be null"); } WebElement taskRow = findTaskRow(taskName); if (taskRow != null) { findAndWait(By.xpath("//a[text()='" + taskName + "']")); try { taskRow.click(); WebElement lastTD = taskRow.findElement(By.cssSelector("td:last-of-type")); mouseOver(lastTD); lastTD.findElement(action).click(); } catch (StaleElementReferenceException ex) { Actions mouseOver = new Actions(driver); mouseOver.moveToElement(driver.findElement(By.xpath("//a[text()='" + taskName + "']"))) .moveToElement(taskRow.findElement(By.cssSelector("td:last-of-type"))) .moveToElement(driver.findElement(action)).moveToElement(driver.findElement(action)).click() .perform(); } } else { throw new PageException("File not found"); } }
From source file:org.alfresco.po.share.search.FacetedSearchView.java
License:Open Source License
/** * Open the sort menu.//from w ww . j ava 2s . c om */ private void openMenu() { driver.findElement(By.cssSelector("#FCTSRCH_RESULTS_MENU")).click(); // Regain page control from dojo WebElement element = driver.findElement(By.cssSelector("img.alf-configure-icon")); Actions action = new Actions(driver); action.moveToElement(element).click().perform(); }
From source file:org.alfresco.po.share.search.GalleryViewPopupPage.java
License:Open Source License
/** * Select close button.//from w ww . ja va 2s . co m * * @return {@link FacetedSearchPage} page response */ public HtmlPage selectClose() { closeButton = driver.findElement(GALLERY_VIEW_CLOSE_BUTTON); Actions a = new Actions(driver); a.moveToElement(closeButton); a.click(); a.perform(); return factoryPage.instantiatePage(driver, FacetedSearchPage.class); }
From source file:org.alfresco.po.share.search.PreViewPopUpPage.java
License:Open Source License
/** * Select close button.//www .j a va 2s . c o m * * @return {@link FacetedSearchPage} page response */ public HtmlPage selectClose() { closeButton = driver.findElement(PREVIEW_CLOSE_BUTTON); Actions a = new Actions(driver); a.moveToElement(closeButton); a.click(); a.perform(); driver.findElements(PREVIEW_CLOSE_BUTTON); return factoryPage.instantiatePage(driver, FacetedSearchPage.class); }
From source file:org.aludratest.service.gui.web.selenium.selenium2.condition.MixedElementCondition.java
License:Apache License
@Override protected WebElement applyOnElement(WebElement element) { // check if it is in foreground if (zIndexSupport != null && !zIndexSupport.isInForeground(element)) { this.message = "Element not in foreground"; return null; }/*w w w .j a va 2s .c o m*/ // check visibility if required if (visible && !element.isDisplayed()) { // try to scroll to element try { Actions actions = new Actions(locatorSupport.getDriver()); actions.moveToElement(LocatorSupport.unwrap(element)).perform(); } catch (Throwable t) { // ignore } if (!element.isDisplayed()) { this.message = "Element not visible"; return null; } } if (enabled && !element.isEnabled()) { this.message = "Element not enabled"; return null; } return element; }