List of usage examples for org.openqa.selenium.interactions Actions build
public Action build()
From source file:com.vaadin.testbench.elements.MenuBarElement.java
License:Apache License
private void activateOrOpenSubmenu(WebElement item, boolean alwaysClick) { if (lastItemLocationMovedTo == null || !isAnySubmenuVisible()) { item.click();//from w ww . ja v a2s .c o m if (hasSubmenu(item)) { lastItemLocationMovedTo = item.getLocation(); } return; } // Assumes mouse is still at position of last clicked element Actions action = new Actions(getDriver()); action.moveToElement(item); action.build().perform(); if (isLeaf(item) || isSelectedTopLevelItem(item)) { lastItemLocationMovedTo = null; } else { lastItemLocationMovedTo = item.getLocation(); } if (alwaysClick || isLeaf(item) || !isAnySubmenuVisible()) { action = new Actions(getDriver()); action.click(); action.build().perform(); } }
From source file:com.vaadin.testbench.elements.WindowElement.java
License:Apache License
/** * Moves the window by given offset.// www.j a v a2 s.c om * * @param xOffset * x offset * @param yOffset * y offset */ public void move(int xOffset, int yOffset) { Actions action = new Actions(getDriver()); action.moveToElement(findElement(org.openqa.selenium.By.className("v-window-wrap")), 5, 5); action.clickAndHold(); action.moveByOffset(xOffset, yOffset); action.release(); action.build().perform(); }
From source file:com.vaadin.testbench.TestBenchElement.java
@Override public void click(int x, int y, Keys... modifiers) { waitForVaadin();/*w w w .j a va 2s . c o m*/ Actions actions = new Actions(getCommandExecutor().getWrappedDriver()); actions.moveToElement(actualElement, x, y); // Press any modifier keys for (Keys modifier : modifiers) { actions.keyDown(modifier); } actions.click(); // Release any modifier keys for (Keys modifier : modifiers) { actions.keyUp(modifier); } actions.build().perform(); }
From source file:com.vaadin.tests.components.calendar.CalendarResizeOverlappingEventsTest.java
License:Apache License
private void dragAndDrop(WebElement element, int yOffset) { /*/*from www .j a v a2s . com*/ * Selenium doesn't properly drag and drop items in IE8. It tries to * start dragging an element from a position above the element itself. */ if (BrowserUtil.isIE8(getDesiredCapabilities())) { Actions action = new Actions(getDriver()); action.moveToElement(element); action.moveByOffset(0, 1); action.clickAndHold(); action.moveByOffset(0, yOffset); action.release(); action.build().perform(); } else { Actions action = new Actions(getDriver()); action.dragAndDropBy(element, 0, yOffset); action.build().perform(); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Clicks on a link, button, checkbox or radio button. If the click action * causes a new page to load (like a link usually does), call * waitForPageToLoad. <br>// ww w. j a va 2s . co m * ClickAt is capable of perform clicking on a relative location to the * specified element. use locator to specify the respective X,Y coordinates * to click * * @param locator * : Logical name of the web element assigned by the automation * scripter * @param coordinateString * the coordinate string */ private void doClickAt(final ObjectLocator locator, final String coordinateString) { String objectID = ""; int counter = getRetryCount(); int xOffset = 0; int yOffset = 0; WebDriver driver = getDriver(); String objectName = locator.getLogicalName(); try { // Retrieve the correct object locator from the object map objectID = locator.getActualLocator(); // first verify whether the element is present in the current web // page checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); try { xOffset = Integer.parseInt((coordinateString.split(",")[0]).trim()); yOffset = Integer.parseInt((coordinateString.split(",")[1]).trim()); } catch (Exception e) { e.printStackTrace(); reportresult(true, "CLICKAT :" + objectName + "", "FAILED", "CLICKAT coordinate string (" + coordinateString + ") for :Element (" + objectName + ") [" + objectID + "] is invalid"); checkTrue(false, true, "CLICKAT coordinate string (" + coordinateString + ") " + "for :Element (" + objectName + ") [" + objectID + "] is invalid"); } /* * START DESCRIPTION following while loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; // call for real selenium command /* selenium.clickAt(objectID, coordinateString); */ Actions clickAt = new Actions(driver); clickAt.moveToElement(element, xOffset, yOffset).click(); clickAt.build().perform(); // if not exception is called consider and report the result // as passed reportresult(true, "CLICKAT :" + locator.getLogicalName() + "", "PASSED", ""); // if the testcase passed move out from the loop break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "CLICKAT :" + objectName + "", "FAILED", "CLICKAT command cannot access Element (" + locator + ") [" + objectID + "] "); checkTrue(false, true, "CLICKAT command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { e.printStackTrace(); /* * VTAF result reporter call */ reportresult(true, "CLICKAT :" + objectName + "", "FAILED", "CLICKAT command :Element (" + objectName + ") [" + objectID + "] not present"); /* * VTAF specific validation framework reporting */ checkTrue(false, true, "CLICKAT command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Double clicks on a link, button, checkbox or radio button. If the double * click action causes a new page to load <br> * (like a link usually does), call waitForPageToLoad. <br> * <br>/*from ww w . j a v a 2 s .c o m*/ * * @param locator * the locator */ private void doDoubleClick(final ObjectLocator locator) { // Retrieve the actual object name from the object repository int counter = getRetryCount(); WebDriver driver = getDriver(); String objectName = locator.getLogicalName(); String objectID = locator.getActualLocator(); try { // First chacking whether the element is present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; element.click(); Actions dClick = new Actions(driver); dClick.moveToElement(element).doubleClick(); dClick.build().perform(); /* selenium.doubleClick(objectID); */ reportresult(true, "DOUBLE CLICK :" + objectName + "", "PASSED", ""); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "DOUBLE CLICK :" + objectName + "", "FAILED", "DOUBLE CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); checkTrue(false, true, "DOUBLE CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if object not found exception is raised fail the test cases e.printStackTrace(); reportresult(true, "DOUBLE CLICK :" + objectName + "", "FAILED", "DOUBLE CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "DOUBLE CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Doubleclicks on a link, button, checkbox or radio button. If the action * causes a new page to load (like a link usually does), call * waitForPageToLoad.<br>/*from w ww. j av a 2 s. c o m*/ * The main differentiator of <b> DoubleClickAt </b> is, user can make the * script click on a relative location to the element <br> * <br> * * @param locator * : the coordination string to be click which is relative to the * element <br> * this should be specified using relative X and Y coordinates, * in the following format "X,Y" * @param coordinateString * the coordinate string */ private void doDoubleClickAt(final ObjectLocator locator, final String coordinateString) { int counter = getRetryCount(); int xOffset = 0; int yOffset = 0; WebDriver driver = getDriver(); // Retrieve the actual object identification from the OR String objectID = locator.getActualLocator(); String objectName = locator.getLogicalName(); try { // Precheck done to check whether the element is available if // element is not // present, code will move to the catch block and report an error checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); try { xOffset = Integer.parseInt((coordinateString.split(",")[0]).trim()); yOffset = Integer.parseInt((coordinateString.split(",")[1]).trim()); } catch (Exception e) { e.printStackTrace(); reportresult(true, "DOUBLE CLICK AT :" + objectName + "", "FAILED", "DOUBLE CLICK AT coordinate string (" + coordinateString + ") for :Element (" + objectName + ") [" + objectID + "] is invalid"); checkTrue(false, true, "DOUBLE CLICK AT coordinate string (" + coordinateString + ") " + "for :Element (" + objectName + ") [" + objectID + "] is invalid"); } /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { counter--; try { Actions doubleClickAt = new Actions(driver); doubleClickAt.moveToElement(element, xOffset, yOffset).doubleClick(); doubleClickAt.build().perform(); reportresult(true, "DOUBLE CLICK AT :" + objectName + "", "PASSED", ""); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); // The main possibility of throwing exception at this point // should be due to the element was not // fully loaded, in this catch block handle the exception // untill retry amount of attempts if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "DOUBLE CLICK AT :" + objectName + "", "FAILED", "DOUBLE CLICK AT command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "DOUBLE CLICK AT command :Element (" + objectName + ") [" + objectID + "] not present"); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if any exception was raised report report an error and fail the // test case e.printStackTrace(); reportresult(true, "DOUBLE CLICK AT :" + objectName + "", "FAILED", "DOUBLE CLICK AT command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "DOUBLE CLICK AT command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Right clicks on an web element.// www .j av a 2 s. c o m * * @param objectName * : Logical name of the object to be doubleclicked. * * */ public final void rightClick(final String objectName) { // Retrieve the actual object name from the object repository String objectID = ObjectMap.getObjectSearchPath(objectName, locatorIdentifire); int counter = getRetryCount(); try { // First chacking whether the element is present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; Actions rClick = new Actions(getDriver()); rClick.moveToElement(element).contextClick(element); rClick.build().perform(); /* selenium.doubleClick(objectID); */ reportresult(true, "RIGHT CLICK :" + objectName + "", "PASSED", ""); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { // TODO Auto-generated catch block if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "RIGHT CLICK :" + objectName + "", "FAILED", "RIGHT CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); checkTrue(false, true, "RIGHT CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if object not found exception is raised fail the test cases e.printStackTrace(); reportresult(true, "RIGHT CLICK :" + objectName + "", "FAILED", "RIGHT CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "RIGHT CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:GlennsPack.GlennWebAPI.Bot2048.java
License:Open Source License
public Bot2048() { System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().setSize(new Dimension(2000, 800)); driver.get("http://annimon.github.io/16384/"); // try { // Thread.sleep(2000); // } catch (Exception e) { // // FIXME: handle exception // }//from www. j a v a 2s . c om // WebElement element = driver.findElement(By.xpath("/html/body/div")); // ("/html/body/div/div[2]")); Actions actions = new Actions(driver); actions.moveToElement(element); actions.click(); CharSequence[] array = { Keys.ARROW_DOWN, Keys.ARROW_LEFT, Keys.ARROW_RIGHT }; for (int i = 0; i < 1000000; i++) { Random random = new Random(); actions.sendKeys(array[random.nextInt(3)]); ; actions.sendKeys(Keys.ARROW_DOWN); actions.build().perform(); try { // Thread.sleep(1); } catch (Exception e) { // FIXME: handle exception } } }
From source file:GlennsPack.GlennWebAPI.Keybr.java
License:Open Source License
public void runer(WebDriver driver) { driver.findElement(By.className("Tour-close")).click(); System.out.println("CLICKED"); ////from ww w .ja v a 2 s .c o m try { driver.findElement(By.id("Practice-textInput")).click(); Thread.sleep(1000); WebElement element = driver.findElement(By.id("Practice")); Actions actions = new Actions(driver); actions.moveToElement(element); actions.click(); String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[]-.,?!()\"'"; Robot robot = new Robot(); for (int i1 = 0; i1 < 30; i1++) { try { for (int i = 0; i < 200; i++) { String currLetter = driver .findElement(By.cssSelector("span.TextInput-item:nth-child(" + (i + 1) + ")")) .getText(); System.out.println(currLetter); if (!abc.contains(currLetter)) { currLetter = " "; System.out.println("SPACE"); i++; } Thread.sleep(25); robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0))); actions.build().perform(); robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0))); } } catch (Exception e) { System.out.println("Another row done"); } } } catch (Exception e) { e.printStackTrace(); } }