List of usage examples for org.openqa.selenium.interactions Actions build
public Action build()
From source file:org.cerberus.serviceEngine.impl.WebDriverService.java
License:Open Source License
@Override public MessageEvent doSeleniumActionMouseUp(Session session, String string1, String string2) { MessageEvent message;/*from w ww .j av a2 s.c o m*/ try { if (!StringUtil.isNull(string1)) { try { Actions actions = new Actions(session.getDriver()); actions.release(this.getSeleniumElement(session, string1, true, true)); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEUP); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string1)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEUP_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string1)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } else if (!StringUtil.isNull(string2)) { try { Actions actions = new Actions(session.getDriver()); actions.release(this.getSeleniumElement(session, string1, true, true)); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEUP); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string2)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEUP_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string2)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_CLICK); }
From source file:org.cerberus.serviceEngine.impl.WebDriverService.java
License:Open Source License
@Override public MessageEvent doSeleniumActionDoubleClick(Session session, String html, String property) { MessageEvent message;//from w w w.j a va 2 s.c om try { Actions actions = new Actions(session.getDriver()); if (!StringUtil.isNull(property)) { try { WebElement element = this.getSeleniumElement(session, property, true, true); actions.doubleClick(element); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DOUBLECLICK); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } else if (!StringUtil.isNull(html)) { try { WebElement element = this.getSeleniumElement(session, html, true, true); actions.doubleClick(element); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DOUBLECLICK); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", html)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", html)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK); }
From source file:org.cerberus.serviceEngine.impl.WebDriverService.java
License:Open Source License
@Override public MessageEvent doSeleniumActionMouseOver(Session session, String html, String property) { MessageEvent message;/* w ww . j a va 2 s. c o m*/ try { if (!StringUtil.isNull(html)) { try { Actions actions = new Actions(session.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(session, html, true, true); actions.moveToElement(menuHoverLink); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", html)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", html)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } else if (!StringUtil.isNull(property)) { try { Actions actions = new Actions(session.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(session, property, true, true); actions.moveToElement(menuHoverLink); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER); }
From source file:org.cerberus.serviceEngine.impl.WebDriverService.java
License:Open Source License
@Override public MessageEvent doSeleniumActionMouseOverAndWait(Session session, String actionObject, String actionProperty) {/*from w w w . ja v a 2 s . com*/ MessageEvent message; try { if (!StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { if (StringUtil.isNumeric(actionProperty)) { try { Actions actions = new Actions(session.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(session, actionObject, true, true); actions.moveToElement(menuHoverLink); actions.build().perform(); int sleep = Integer.parseInt(actionProperty); try { Thread.sleep(sleep); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVERANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } catch (InterruptedException e) { MyLogger.log(WebDriverService.class.getName(), Level.INFO, e.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT1%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_NO_NUMERIC); message.setDescription(message.getDescription().replaceAll("%TIME%", actionProperty)); return message; } else if (StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { try { Actions actions = new Actions(session.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(session, actionObject, true, true); actions.moveToElement(menuHoverLink); actions.build().perform(); } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICKANDNOWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); return message; } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC); }
From source file:org.cerberus.serviceEngine.impl.WebDriverService.java
License:Open Source License
@Override public MessageEvent doSeleniumActionMouseDownMouseUp(Session session, String string1, String string2) { MessageEvent message;// ww w. ja v a 2 s .c om try { if (!StringUtil.isNull(string1)) { try { Actions actions = new Actions(session.getDriver()); actions.clickAndHold(this.getSeleniumElement(session, string1, true, false)); actions.build().perform(); actions.release(this.getSeleniumElement(session, string1, true, false)); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEDOWN); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string1)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string1)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } else if (!StringUtil.isNull(string2)) { try { Actions actions = new Actions(session.getDriver()); actions.clickAndHold(this.getSeleniumElement(session, string1, true, false)); actions.build().perform(); actions.release(this.getSeleniumElement(session, string1, true, false)); actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEDOWN); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string1)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", string2)); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString()); return message; } } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_CLICK); }
From source file:org.evilco.bot.powersweeper.game.ScreenGameInterface.java
License:Apache License
/** * {@inheritDoc}/*from w ww .j a v a2s . c o m*/ */ @Override public void flagTile(TileLocation location) { // check chunk location if (this.chunkLocation == null || !this.chunkLocation.equals(location.getChunk().getLocation())) this.moveToChunk(location.getChunk().getLocation()); // prepare action Actions actions = this.buildTileAction(location.getX(), location.getY()); // click actions.contextClick(); // perform if (hasQueue()) { actionsQueue.add(actions.build()); } else { actions.build().perform(); } }
From source file:org.evilco.bot.powersweeper.game.ScreenGameInterface.java
License:Apache License
/** * {@inheritDoc}//from w w w .ja v a 2 s . c o m */ @Override public void moveToChunk(@NonNull ChunkLocation location) { getLogger().entry(); // check whether sane movement is possible if (this.chunkLocation != null) { // calculate distance ChunkLocation distance = this.chunkLocation.getDistance(location); ChunkLocation distanceSanitized = new ChunkLocation(distance); distanceSanitized.sanitize(); // verify whether sane movement is possible if (distanceSanitized.getX() <= SANE_MOVEMENT_THRESHOLD && distanceSanitized.getY() <= SANE_MOVEMENT_THRESHOLD) { // calculate distance long x = ((this.chunk.getWidth() * CELL_SIZE) * distance.getX()); long y = ((this.chunk.getHeight() * CELL_SIZE) * distance.getY()); // verify if (x > Integer.MAX_VALUE || y > Integer.MAX_VALUE) getLogger().warn("Sane movement threshold of " + SANE_MOVEMENT_THRESHOLD + " seems to be too big. Aborting."); else { // find HTML WebElement html = this.getPowersweeper().getDriverManager().getDriver() .findElement(By.tagName("html")); // build action Actions action = new Actions(this.getPowersweeper().getDriverManager().getDriver()); action.moveToElement(html, (CELL_SIZE / 2), (CELL_SIZE / 2)); action.clickAndHold(); action.moveByOffset(((int) x), ((int) y)); action.release(); // execute action.build().perform(); // wait for a few seconds try { Thread.sleep(2000); } catch (Exception ex) { getLogger().warn("Aliens wake us up to early."); } // update location this.chunkLocation = location; // force update this.update(); // trace getLogger().exit(); // skip return; } } } // open new URL this.getPowersweeper().getDriverManager().getDriver() .get(String.format(GAME_URL, location.getX(), location.getY())); // wait for a few seconds try { Thread.sleep(5000); } catch (Exception ex) { getLogger().warn("Aliens wake us up to early."); } // update location this.chunkLocation = location; // force update this.update(); // trace getLogger().exit(); }
From source file:org.evilco.bot.powersweeper.game.ScreenGameInterface.java
License:Apache License
/** * {@inheritDoc}/*from ww w .ja va 2 s . c om*/ */ @Override public void touchTile(TileLocation location) { // check chunk location if (this.chunkLocation == null || !this.chunkLocation.equals(location.getChunk().getLocation())) this.moveToChunk(location.getChunk().getLocation()); // prepare action Actions actions = this.buildTileAction(location.getX(), location.getY()); // click actions.click(); // perform actions.build().perform(); }
From source file:org.jitsi.meet.test.DisplayNameTest.java
License:Apache License
/** * Check whether name has changed locally. * @param newName the name we changed//from w w w. j ava 2 s. com */ public void doLocalDisplayNameCheck(String newName) { System.err.println("Start doLocalDisplayNameCheck for " + newName + "."); WebDriver secondParticipant = ConferenceFixture.getSecondParticipant(); // make sure we hover over other element first, cause when hovering // local element we may not out of it when editing WebElement remoteVideoElem = secondParticipant.findElement(By .xpath("//span[@id='participant_" + MeetUtils.getResourceJid(ConferenceFixture.getOwner()) + "']")); Actions action0 = new Actions(secondParticipant); action0.moveToElement(remoteVideoElem); action0.perform(); // now lets check whether display name is set locally WebElement displayNameElem = secondParticipant .findElement(By.xpath("//span[@id='localVideoContainer']" + "//span[@id='localDisplayName']")); // hover over local display name WebElement localVideoContainerElem = secondParticipant .findElement(By.xpath("//span[@id='localVideoContainer']")); Actions action = new Actions(secondParticipant); action.moveToElement(localVideoContainerElem); action.build().perform(); boolean isFF = ConferenceFixture.getBrowserType(secondParticipant) == ConferenceFixture.BrowserType.firefox; if (!isFF) { assertTrue("Display name not visible", displayNameElem.isDisplayed()); } String displayNameText = displayNameElem.getText(); // there is a bug in FF with hovering over elements // so we workaround this if (isFF) { displayNameText = displayNameElem.getAttribute("innerHTML"); } if (newName != null && newName.length() > 0) assertTrue("Display name not changed! Content of elem is: " + displayNameText, displayNameText.contains(newName)); else assertTrue("Display name is not removed! (" + displayNameText + ")", displayNameText.equals(DEFAULT_DISPLAY_NAME)); }
From source file:org.kuali.rice.krad.demo.uif.library.controls.LibraryControlCheckboxDefaultAft.java
License:Educational Community License
protected void actionSendKeysArrowDown(String id) { Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id(id))); actions.click();//from w w w . ja va 2 s. co m actions.sendKeys(Keys.ARROW_DOWN); actions.build().perform(); }