- Common ways to obtain Actions
private void myMethod () {}
WebElement svgObject = driver.findElement(By.xpath(YOUR XPATH)); Actions builder = new Actions(driver); builder.click(svgObject).build().perform();
Actions actions = new Actions(driver); WebElement menuHoverLink = driver.findElement(By.linkText("Menu heading")); actions.moveToElement(menuHoverLink); WebElement subLink = driver.findElement(By.cssSelector("#headerMenu .subLink")); actions.moveToElement(subLink); actions.click(); actions.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(); } } }
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 ClearAndSetText(By by, string text) { WebElement element = driver.findElement(by); Actions navigator = new Actions(driver); navigator.click(element) .sendKeys(Keys.END) .keyDown(Keys.SHIFT) .sendKeys(Keys.HOME) .keyUp(Keys.SHIFT) .sendKeys(Keys.BACK_SPACE) .sendKeys(text) .perform(); }
driver.findElement(By.xpath("id=menu")).click(); WebElement subMenu=driver.findElement(By.xpath("id=sub_menu_a")); Actions myaction = new Actions(driver); myaction.moveToElement(subMenu); WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.elementToBeClickable(subMenu)); myaction.click().perform();
Actions actions = new Actions(driver); WebElement menuHoverLink = driver.findElement(By.linkText(hoverMenu)); actions.moveToElement(menuHoverLink); WebElement submenu = new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfNestedElementLocatedBy(menuHoverLink, By.xpath(".//span[.='" + subMenuName + "']"))) actions.moveToElement(submenu); actions.click().perform();
WebDriver driver=new FirefoxDriver(); driver.get("http://www.kgisliim.ac.in/"); Actions actions=new Actions(driver); WebElement menuHoverLink=driver.findElement(By.linkText("Alumni")); actions.moveToElement(menuHoverLink); //driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); WebElement subLink=driver.findElement(By.cssSelector(".options>ul>li>a")); actions.moveToElement(subLink); actions.click(); actions.perform();
Actions actionobj = new Actions(fd1); actionobj.moveToElement(heatmap); actionobj.pause(10000); //wait 10 seconds actionobj.click(heatmap); actionobj.perform();
Actions actions = new Actions(driver); actions.moveToElement(element); actions.click(); actions.sendKeys("Some Name"); actions.build().perform();
/** * 选择最近7天数据 */ public static void clickCurrentSevenDaysData(WebDriver webdriver, Actions builder) { WebElement currElement = webdriver.findElement(By.linkText("7天")); builder.moveToElement(currElement).click().build().perform(); Wait.waitForLoad(webdriver); }
@When("^" + THAT + THE_USER + " " + INPUT + " " + QUOTED_CONTENT + "$") public void that_we_input(String content) { content = valueOf(content); if (element.getTagName().equals("input") && "file".equals(element.getAttribute("type"))) { if (driverWrapper.getDriver() instanceof GridWebDriver) { ((RemoteWebElement) element).setFileDetector(new LocalFileDetector()); } element.sendKeys(content); } else { new Actions(driver).moveToElement(element).click().sendKeys(content).build().perform(); } }
public void clickCenter() { invoker.doJAction("Click in Center of Element", () -> { Actions builder = new Actions(getDriver()); builder.click(getWebElement()).perform(); }); }
public void clickByXY(int x, int y) { invoker.doJAction(format("Click on Element with coordinates (x,y) = (%s, %s)", x, y), () -> new Actions(getDriver()) .moveToElement(getWebElement(), x, y).click().build().perform()); } }
@Override protected void doPerform() { WebElement source = isSourceDocumentRoot() ? null : getFirstElement(); if (offset != null) { Point offsetPoint = offset.offset(getSize()); getActions().moveToElement(source, offsetPoint.x(), offsetPoint.y()).click().perform(); } else { getFirstElement().click(); } } }
public void clickVolumeButton() { builder.moveToElement(driver.findElement(PLAYER_SELECTOR)) .pause(1000) .moveToElement(volumeButton, 30, 30) .click() .perform(); }