// Configure the action Actions builder = new Actions(driver); builder.keyDown(Keys.CONTROL) .click(someElement) .click(someOtherElement) .keyUp(Keys.CONTROL); // Then get the action: Action selectMultiple = builder.build(); // And execute it: selectMultiple.perform();
protected void click(Driver driver, WebElement element, int offsetX, int offsetY) { if (driver.config().clickViaJs()) { driver.executeJavaScript("arguments[0].dispatchEvent(new MouseEvent('click', {" + "'view': window," + "'bubbles': true," + "'cancelable': true," + "'clientX': arguments[0].getClientRects()[0].left + arguments[1]," + "'clientY': arguments[0].getClientRects()[0].top + arguments[2]" + "}))", element, offsetX, offsetY); } else { driver.actions() .moveToElement(element, offsetX, offsetY) .click() .build() .perform(); } } }
@BeforeEach public void setup(@TempDirectory.TempDir Path folder) throws IOException { Assumptions.assumeTrue(Boolean.getBoolean("smoke.test"), "Smoke tests disabled (set System property 'smoke.test')"); this.downloadDir = folder.toFile(); FirefoxProfile fxProfile = new FirefoxProfile(); fxProfile.setPreference("browser.download.folderList", 2); fxProfile.setPreference("browser.download.manager.showWhenStarting", false); fxProfile.setPreference("browser.download.dir", this.downloadDir.getAbsolutePath()); fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/x-compress,application/octet-stream"); FirefoxOptions options = new FirefoxOptions().setProfile(fxProfile); this.driver = new FirefoxDriver(options); ((JavascriptExecutor) this.driver).executeScript("window.focus();"); Actions actions = new Actions(this.driver); this.enterAction = actions.sendKeys(Keys.ENTER).build(); }
Actions actions = new Actions(driver); actions.moveToElement(website); actions.click(); actions.sendKeys("Some Name"); actions.build().perform();
public void verifyProfilePhoto(String courseId, String studentName, String urlRegex) { String rowId = getStudentRowId(courseId, studentName); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.tagName("img")) .getAttribute("src")); WebElement photo = browser.driver.findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".profile-pic-icon-click > img")); JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver; jsExecutor.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -100);", photo); Actions action = new Actions(browser.driver); action.click(photo).build().perform(); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".popover-content > .profile-pic")) .getAttribute("src")); }
/** * Scrolls element to first cell in spreadsheet, clicks on it and sends the value as keystrokes. */ void scrollElementToFirstCellAndSendKeys(WebElement spreadsheetElement, String value) { new Actions(browser.driver).moveToElement(spreadsheetElement) .click().sendKeys(value).build().perform(); }
public void dragAndDropQuestionOption(String qnType, int qnNumber, int sourceIndex, int targetIndex) throws Exception { WebElement draggedOptionElement = browser.driver.findElement(By.xpath("//div[@id='" + qnType + "OptionRow-" + sourceIndex + "-" + qnNumber + "']//span[@class='glyphicon glyphicon-resize-vertical']")); WebElement targetElement = browser.driver.findElement(By.xpath("//div[@id='" + qnType + "OptionRow-" + targetIndex + "-" + qnNumber + "']//span[@class='glyphicon glyphicon-resize-vertical']")); Actions builder = new Actions(browser.driver); // drag option to target, move 10 units above target and release // multiple movements are used to slow down drag movement and provide // enough time for the grid to create empty slots builder.clickAndHold(draggedOptionElement) .moveToElement(targetElement) .moveToElement(targetElement, 0, -10) .release() .build() .perform(); }
/** * A convenience method for performing the actions without calling build() first. */ public void perform() { build().perform(); }
WebElement element = panel.findElement(By.className("tabComboBoxButton")); Actions builder = new Actions(this.driver); builder.moveToElement(element); builder.click(); builder.build().perform();
Actions actions = new Actions(driver); actions.moveToElement(element); actions.click(); actions.sendKeys("Some Name"); actions.build().perform();
public void select_upto(Element other_element) { Actions actions = new Actions(browser.driver()); actions.moveToElement(_nativeWebElement()).build().perform(); wait_between_steps_plus(1); actions.clickAndHold(_nativeWebElement()).build().perform(); wait_between_steps_plus(1); actions.moveToElement(other_element._nativeWebElement()).build().perform(); wait_between_steps_plus(1); actions.release().build().perform(); }
/** * Send keys through composite actions * /!\ does not clear text before and no blur after * * @param keysToSend */ @ReplayOnError public void sendKeysAction(CharSequence... keysToSend) { findElement(true); new Actions(driver).sendKeys(element, keysToSend).build().perform(); }
@Step("{0} hovers over #target") @Override public <T extends Actor> void performAs(T theActor) { as(theActor).moveToElement(resolveElementFor(theActor)).build().perform(); }
@Override public void dbClick() { Actions action = new Actions(frontEndDriver.getWebDriver()); WebElement find = frontEndDriver.find(wrappedElement); Action doubleClick = action.doubleClick(find).build(); doubleClick.perform(); }
@Override public void doHover(Integer xOffset, Integer yOffset) { DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()), Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); if (xOffset != null && yOffset!= null) { action.moveToElement(element, xOffset, yOffset).build().perform(); } else { action.moveToElement(element).build().perform(); } }
public void dragAndDrop(Element target) { invoker.doJAction(format("Drag and drop to Target Element: %s", target.toString()), () -> new Actions(getDriver()).dragAndDrop(getWebElement(), target.getWebElement()).build() .perform()); } }
@Override public boolean run(TestRun ctx) { new Actions(ctx.driver()).clickAndHold(ctx.locator("locator").find(ctx)).build().perform(); return true; } }
public EditIssueTypeSchemePage selectIssueType(String issueType) { final WebElement source = getIssueTypeListItemFromAvailableOptions(issueType); assertNotNull("Could not find element for issue type in 'Available Options'.", source); final Actions actions = new Actions(driver) .dragAndDrop(source, selectedOptionsWebElement); ((Locatable)source).getCoordinates().inViewPort(); //scrolls the page to make this element visible in the viewport actions.build().perform(); return this; }
@Override public void doDoubleClick() { DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); action.moveToElement(element).doubleClick(element).build().perform(); }
@Override public void doRightClick() { DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); action.moveToElement(element).contextClick(element).build().perform(); }