List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:org.sonarqube.qa.util.pageobjects.measures.MeasuresPage.java
License:Open Source License
public MeasuresPage backShortcut() { SelenideElement panel = Selenide.$(".layout-page-header-panel"); // panel.sendKeys(Keys.LEFT) does not work correctly on Chrome // The workaround is to use Actions // https://bugs.chromium.org/p/chromedriver/issues/detail?id=35 Actions actions = new Actions(WebDriverRunner.getWebDriver()); actions.moveToElement(panel); actions.click();// w ww .j a v a2 s . c o m actions.sendKeys(Keys.LEFT); actions.build().perform(); return this; }
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Moves the mouse cursor to the displayed web element. * /*from w ww . java2 s.co m*/ * @param elementListKey * key in the element list to find the technical locator * @param replaceArgs * values to replace the place holders in the element list entry * @return always {@code true} to show inside FitNesse a positive result * @throws StopTestException * if element not available (hidden, not present) or a timeout * occurred */ public boolean moveMouseToElement(String elementListKey, String... replaceArgs) throws StopTestException { WebElement element = findAvailableWebElement(elementListKey, replaceArgs); Actions actions = new Actions(webDriver); actions.moveToElement(element).build().perform(); return true; }
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Double clicks on an element.//w ww .java2 s .co m * * @param elementListKey * key in the element list to find the technical locator * @param replaceArgs * values to replace the place holders in the element list entry * @return always {@code true} to show inside FitNesse a positive result * @throws StopTestException * if element not available (hidden, not present) or a timeout * occurred */ public boolean doubleClickElement(String elementListKey, String... replaceArgs) throws StopTestException { WebElement element = findAvailableWebElement(elementListKey, replaceArgs); Actions action = new Actions(webDriver); action.moveToElement(element).doubleClick().build().perform(); return true; }
From source file:org.testeditor.fixture.web.WebFixture.java
License:Open Source License
/** * Simulates a MouseOver on a Menu. Moves to the given Gui-Element. * /* w w w. ja v a 2 s.co m*/ * FitNesse usage..: |move to element;|arg1|[arg2, arg3, ...]| <br /> * FitNesse example: |move to element;|IconInRow{0}Col{1}|[5, 3]| <br /> * <br /> * * @param elementListKey * the Gui-Element where to move. * @param replaceArgs * values to replace the place holders in the element list entry * with * @return true if WebElement is found and Mouse moved to this Element to * perform an Action. */ public boolean moveToElement(String elementListKey, String... replaceArgs) { boolean result = false; WebElement element = findWebelement(elementListKey, replaceArgs); if (element != null && element.isDisplayed()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("element found ready for Action (moveToElement)"); } Actions actions = new Actions(webDriver); actions.moveToElement(element).build().perform(); result = true; } return result; }
From source file:org.testeditor.fixture.web.WebFixture.java
License:Open Source License
/** * Move to element and click menu.// ww w.j ava 2 s.c om * * @param elementListKey * key of element in elementList.conf. * @param menuEntryKey * key of menu. * @return true if element is found and menu is activated. */ public void moveToElementAndClickMenu(String elementListKey, String menuEntryKey) { WebElement element = findWebelement(elementListKey, new String[] {}); if (element != null && element.isDisplayed()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("element found ready for Action (moveToElement)"); } Actions actions = new Actions(webDriver); actions.moveToElement(element).build().perform(); } click(menuEntryKey); }
From source file:org.webtestingexplorer.actions.HoverAction.java
License:Open Source License
@Override public void perform(WebDriverWrapper driver) { WebElement element = identifier.findElement(driver); Actions builder = new Actions(driver.getDriver()); Actions hoverAction = builder.moveToElement(element); hoverAction.perform();//from w w w .j av a2 s . co m try { Thread.sleep(hoverDelayMillis); } catch (InterruptedException e) { } }
From source file:org.wso2.emm.integration.ui.pages.CommonUtil.java
License:Open Source License
/** * Waits until the given element is clickable and perform the click event. * * @param driver selenium web driver.// ww w.j a v a 2 s. c o m * @param locator locator of the element. * @throws InterruptedException If error occurs with thread execution. */ public static void waitAndClick(WebDriver driver, By locator) throws InterruptedException { Actions actions = new Actions(driver); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.elementToBeClickable(locator)); WebElement webElement = driver.findElement(locator); /* There is a issue in Selenium Chrome Driver where it performs click event in wrong places (#633). Mostly occur when the element to be clicked is placed outside the visible area. To overcome this issue scrolling the page to the element locator through a JavascriptExecutor */ ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", webElement); Thread.sleep(500); actions.moveToElement(webElement).click().build().perform(); }
From source file:org.xmlium.test.web.commons.xml.XMLTestSteps.java
License:LGPL
protected void processStep(StepType step) throws Exception { WebElement element = null;//from www . j av a2 s . c om Alert a = null; if (step.getScrollX() != null && step.getScrollY() != null) { JavascriptExecutor js = (JavascriptExecutor) getSuite().getDriver(); js.executeScript("window.scrollTo(" + step.getScrollX() + ", " + step.getScrollY() + ");"); } if (step.isBack() != null && step.isBack()) { getSuite().getDriver().navigate().back(); } if (step.isForward() != null && step.isForward()) { getSuite().getDriver().navigate().forward(); } Element e = null; if (step.getLoad() != null && step.getLoad().getKey() != null) { e = store.get(step.getLoad().getKey()); element = findElement(e.getFinds()); } if (step.getElement() != null) { if (step.getElement().getFinds() != null) { e = step.getElement(); checkStore(e); element = checkWaitFor(e); if (element == null && step.getElement().isCheckNullElement()) { return; } checkStoreValue(e, element); checkSetValue(e, element); checkSendKeys(e, element); checkClick(e, element); checkChangeState(e); checkText(e, element); checkMoveX(e, element); } } if (step.getSwitchTo() != null) { Object to = switchTo(step.getSwitchTo()); if (to instanceof Alert) { a = (Alert) to; if (step.getSwitchTo().getAlert() != null && step.getSwitchTo().getAlert().isAccept()) { a.accept(); } } else { a = null; } } if (step.getSelect() != null) { org.xmlium.testsuite.Select stepSelect = step.getSelect(); if (element != null && stepSelect.getSelectBy().getByIndex() != null) { Index index = stepSelect.getSelectBy().getByIndex(); SelectData selectData = new SelectData(); initSelectIndexes(element, index, selectData); if (selectData.selectIndex >= 0) { Select select = new Select(element); List<WebElement> options = select.getOptions(); WebElement option = options.get(selectData.selectIndex); option.click(); } else { throw new RuntimeException("selectedIndex=" + selectData.selectIndex); } } else { if (element == null) { element = findElement(step.getSelect().getFinds()); } if (element != null) { Select select = new Select(element); if (step.getSelect().getSelectBy() != null) { selectBy(select, step.getSelect().getSelectBy()); } } } } if (step.getPrettySelect() != null) { PrettySelect stepSelect = step.getPrettySelect(); if (element == null) { if (stepSelect.getFinds() != null) { element = findElement(stepSelect.getFinds()); } } if (element != null && stepSelect.getSelectBy() != null) { SelectData selectData = new SelectData(); Select select = null; select = new Select(element); Index index = null; if (stepSelect.getSelectBy().getByIndex() != null) { index = stepSelect.getSelectBy().getByIndex(); initSelectIndexes(element, index, selectData); } else if (stepSelect.getSelectBy().getByVisibleText() != null) { List<WebElement> elems = select.getOptions(); getOptionIndexBuVisibleText(stepSelect.getSelectBy().getByVisibleText(), elems, selectData); } if (selectData.selectIndex >= 0) { WebElement arrowArea = null; WebElement scrollArea = null; if (stepSelect.getSelectBy().getArrowArea() != null) { arrowArea = findElement(stepSelect.getSelectBy().getArrowArea()); } else { throw new RuntimeException("arrowArea not defined in xml"); } if (arrowArea != null) { arrowArea.click(); if (stepSelect.getSelectBy().getScrollArea() != null) { Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea(); if (scrollAreaFinds.getFind() != null) { scrollArea = findElement(scrollAreaFinds.getFind()); } else if (scrollAreaFinds.getWaitFor() != null) { scrollArea = waitFor(scrollAreaFinds.getWaitFor()); } if (scrollArea == null) { if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) { String text = ""; if (scrollAreaFinds.getFind() != null && scrollAreaFinds.getFind().getByXPath() != null) { text = unformatValue(scrollAreaFinds.getFind().isUnformat(), scrollAreaFinds.getFind().getByXPath().getValue()); } else if (scrollAreaFinds.getWaitFor() != null && scrollAreaFinds.getWaitFor().getByXPath() != null) { text = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(), scrollAreaFinds.getWaitFor().getByXPath().getValue()); } throw new RuntimeException("scrollArea not found: " + text); } else { throw new RuntimeException("scrollArea not defined in xml"); } } } if (index.isFirst() != null || index.isLast() != null) { Actions actions = new Actions(getSuite().getDriver()); String text = null; if (index.isFirst() != null && index.isFirst()) { actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform(); } else if (index.isLast() != null && index.isLast()) { actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); } if (index.isFirst() != null && index.isFirst()) { text = select.getOptions().get(0).getText(); } else if (index.isLast() != null && index.isLast()) { text = select.getOptions().get(select.getOptions().size() - 1).getText(); } if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null && !text.isEmpty()) { xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); WebElement optionElemnt = findElement(f); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(optionElemnt)); optionElemnt.click(); } } else { if (selectData.selectIndex < 0 || selectData.selectIndex >= select.getOptions().size()) { throw new RuntimeException("selectIndex: " + selectData.selectIndex + ", options.size: " + select.getOptions().size()); } WebElement option = select.getOptions().get(selectData.selectIndex); String text = option.getText(); if (text == null || text.isEmpty()) { logger.debug("text is null or empty: " + option); text = null; } if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null) { xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); WebElement optionElemnt = findElement(f); Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates(); coordinate.onPage(); coordinate.inViewPort(); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(optionElemnt)); optionElemnt.click(); } } } else { throw new RuntimeException("can't click the arrow"); } } else if (stepSelect.getSelectBy().getByVisibleText() != null) { WebElement arrowArea = null; WebElement scrollArea = null; if (stepSelect.getSelectBy().getArrowArea() != null) { arrowArea = findElement(stepSelect.getSelectBy().getArrowArea()); } else { throw new RuntimeException("arrowArea not defined in xml"); } if (arrowArea != null) { arrowArea.click(); String scrollAreaXPath = null; if (stepSelect.getSelectBy().getScrollArea() != null) { Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea(); if (scrollAreaFinds.getFind() != null) { scrollArea = findElement(scrollAreaFinds.getFind()); } else if (scrollAreaFinds.getWaitFor() != null) { scrollArea = waitFor(scrollAreaFinds.getWaitFor()); } if (scrollAreaXPath == null) { if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) { if (scrollAreaFinds.getFind() != null && scrollAreaFinds.getFind().getByXPath() != null) { scrollAreaXPath = unformatValue(scrollAreaFinds.getFind().isUnformat(), scrollAreaFinds.getFind().getByXPath().getValue()); } else if (scrollAreaFinds.getWaitFor() != null && scrollAreaFinds.getWaitFor().getByXPath() != null) { scrollAreaXPath = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(), scrollAreaFinds.getWaitFor().getByXPath().getValue()); } // throw new RuntimeException("scrollArea // not found: " + text); } else { throw new RuntimeException("scrollArea not defined in xml"); } } } Actions actions = new Actions(getSuite().getDriver()); String text = null; // actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform(); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(scrollArea)); actions.moveToElement(scrollArea).build().perform(); text = stepSelect.getSelectBy().getByVisibleText(); logger.debug("text: " + text); if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null) { xPath.setValue(scrollAreaXPath + "/descendant::" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); logger.debug("xPath: " + xPath); WebElement optionElemnt = findElement(f); Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates(); coordinate.onPage(); coordinate.inViewPort(); wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.visibilityOf(optionElemnt)); actions.moveToElement(optionElemnt).click().build().perform(); } } } else { throw new RuntimeException("selectedIndex=" + selectData.selectIndex); } } else { if (element == null) { element = findElement(step.getPrettySelect().getFinds()); } if (element != null) { Select select = new Select(element); if (step.getPrettySelect().getSelectBy() != null) { selectBy(select, step.getPrettySelect().getSelectBy()); } } } } if (step.getSleepAfter() != null) { long sleep = step.getSleepAfter().longValue(); try { Thread.sleep(sleep); } catch (Exception e2) { // TODO: handle exception } } }
From source file:org.xwiki.annotation.test.po.AnnotationsLabel.java
License:Open Source License
private void hoverOnAnnotationById(String annotationId) { WebElement annotationIcon = getDriver().findElement(By.id(annotationId)); // Move mouse to annotation icon Actions builder = new Actions(getDriver()); builder.moveToElement(annotationIcon).build().perform(); waitUntilElementIsVisible(By.className("annotation-box-view")); }
From source file:org.xwiki.application.webide.test.po.ProjectPage.java
private void displayPlus(WebElement element) { Actions action = new Actions(getDriver()); action.moveToElement(element).build().perform(); }