org.openqa.selenium.interactions.Actions Java Examples

The following examples show how to use org.openqa.selenium.interactions.Actions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreserveOnRefreshShortcutIT.java    From flow with Apache License 2.0 7 votes vote down vote up
@Test
public void replaceComponentAfterRefresh_componentIsReplaced() {
    open();
    if (hasClientIssue("7587")) {
        return;
    }

    waitPageLoad();

    new Actions(getDriver()).sendKeys(Keys.ENTER).build().perform();
    List<WebElement> infos = findElements(By.className("info"));

    Assert.assertEquals(1, infos.size());
    Assert.assertEquals("Clicked", infos.get(0).getText());

    open();

    waitPageLoad();

    new Actions(getDriver()).sendKeys(Keys.ENTER).build().perform();
    infos = findElements(By.className("info"));

    Assert.assertEquals(2, infos.size());
    Assert.assertEquals("Clicked", infos.get(1).getText());

}
 
Example #2
Source File: TableImpl.java    From masquerade with Apache License 2.0 7 votes vote down vote up
@Override
public ElementsCollection selectRows(By rowBy) {
    this.shouldBe(VISIBLE)
            .shouldBe(LOADED)
            .shouldBe(ENABLED);

    ElementsCollection rows = getRows(rowBy);

    WebDriver webDriver = WebDriverRunner.getWebDriver();
    Actions action = new Actions(webDriver);

    for (SelenideElement row : rows) {
        row.shouldNotHave(selectedClass);

        Keys controlKey = getControlKey();

        action.keyDown(controlKey)
                .click(row.getWrappedElement())
                .keyUp(controlKey)
                .build()
                .perform();
    }

    return rows;
}
 
Example #3
Source File: RealHtmlElement.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Drag and drop an element on top of other element
 * @param targetElement the target element
 */
@Override
@PublicAtsApi
public void dragAndDropTo(
                           HtmlElement targetElement ) {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement source = RealHtmlElementLocator.findElement(this);
    WebElement target = RealHtmlElementLocator.findElement(targetElement);

    Actions actionBuilder = new Actions(webDriver);
    Action dragAndDropAction = actionBuilder.clickAndHold(source)
                                            .moveToElement(target, 1, 1)
                                            .release(target)
                                            .build();
    dragAndDropAction.perform();

    // drops the source element in the middle of the target, which in some cases is not doing drop on the right place
    // new Actions( webDriver ).dragAndDrop( source, target ).perform();
}
 
Example #4
Source File: EndToEndTests.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	takeScreenshot("homePageShouldWork-1");

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	takeScreenshot("homePageShouldWork-2");

	driver.navigate().back();
}
 
Example #5
Source File: AaarghFirefoxWhyDostThouMockMe.java    From webDriverExperiments with MIT License 6 votes vote down vote up
private void checkSimpleCtrlBInteractionWorks() {

        driver.get(KEY_CLICK_DISPLAY);

        new Actions(driver).keyDown(Keys.CONTROL).
                sendKeys("b").
                keyUp(Keys.CONTROL).
                perform();

        System.out.println(driver.findElement(By.id("events")).getText());

        assertEquals( "only expected 4 events",
                      4,
                      driver.findElements(
                            By.cssSelector("#events p")).size());
    }
 
Example #6
Source File: EndToEndTests.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	driver.navigate().back();
}
 
Example #7
Source File: TableImpl.java    From masquerade with Apache License 2.0 6 votes vote down vote up
@Override
public SelenideElement deselectRow(By rowBy) {
    this.shouldBe(VISIBLE)
            .shouldBe(ENABLED);

    SelenideElement row = getRow(rowBy)
            .shouldBe(visible)
            .shouldHave(selectedClass);

    WebDriver webDriver = WebDriverRunner.getWebDriver();
    Actions action = new Actions(webDriver);

    Keys controlKey = getControlKey();

    action.keyDown(controlKey)
            .click(row.getWrappedElement())
            .keyUp(controlKey)
            .build()
            .perform();

    return row;
}
 
Example #8
Source File: JMenuTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void subMenu() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));

    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("menu"));
    int i = 2;
    assertMenuItem(menuItems, i++, "A submenu", "", "83");

    /*
     * NOTE: Clicking on the menu again to ensure that MenuManager sets the
     * state of this menu to closed. Without this call the state of the menu
     * remains open and this test or the next test which clicks on the same
     * menu and perform any actions or request attributes will fail. This
     * behavior is noticed on OSX
     */
    new Actions(driver).moveToElement(menu).click().perform();
}
 
Example #9
Source File: MBeanFieldGroupRequiredErrorMessageTest.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("See if can be run with phantomjs and/or update to geckodriver")
public void testErrorMessageForNonNullAnnotatedComponent() throws InterruptedException {
    driver.navigate().to(
        "http://localhost:5678/"
            + MBeanFieldGroupRequiredErrorMessage.class.getCanonicalName());
    new WebDriverWait(driver, 30).until(VaadinConditions::ajaxCallsCompleted);

    WebElement txtField = driver.findElement(By.id("txtStreet"));
    Actions toolAct = new Actions(driver);
    toolAct.moveToElement(txtField).build().perform();
    Thread.sleep(1000);
    WebElement toolTipElement = driver.findElement(By.cssSelector(".v-app.v-overlay-container > .v-tooltip > .popupContent .v-errormessage > div > div"));

    assertThat(toolTipElement.getText(), is(expectedMessage));
}
 
Example #10
Source File: MobileCheckBox.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Check the check box
 */
@Override
@PublicAtsApi
public void check() {

    new MobileElementState(this).waitToBecomeExisting();

    try {
        WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
        if (!checkboxElement.isSelected()) {
            if (appiumDriver instanceof AndroidDriver) {

                // checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
                new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
            } else {

                checkboxElement.click();
            }
        }
    } catch (Exception se) {
        throw new MobileOperationException(this, "check", se);
    }

    UiEngineUtilities.sleep();
}
 
Example #11
Source File: InternalErrorIT.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void internalError_showNotification_clickEsc_refresh() {
    clickButton(UPDATE);

    clickButton("cause-exception");

    Assert.assertTrue("The page should not be immediately refreshed after "
            + "a server-side exception", isMessageUpdated());
    Assert.assertTrue(
            "'Internal error' notification should be present after "
                    + "a server-side exception",
            isInternalErrorNotificationPresent());

    new Actions(getDriver()).sendKeys(Keys.ESCAPE).build().perform();
    try {
        waitUntil(driver -> !isMessageUpdated());
    } catch (TimeoutException e) {
        Assert.fail(
                "After internal error, pressing esc-key should refresh the page, "
                        + "resetting the state of the UI.");
    }
    Assert.assertFalse(
            "'Internal error' notification should be gone after refreshing",
            isInternalErrorNotificationPresent());
}
 
Example #12
Source File: CommandsExplorer.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
public void chooseCommandTypeInContextMenu(String type) {
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          ExpectedConditions.visibilityOfElementLocated(
              By.xpath("//div[@class='popupContent']/select[contains(@class,'gwt-ListBox')]")));
  WebElement commandTypeElement =
      new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
          .until(
              ExpectedConditions.elementToBeClickable(getCommandTypeElementInContextMenu(type)));
  commandTypeElement.click();
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(ExpectedConditions.elementToBeSelected(commandTypeElement));
  // add timeout to be sure webelement ready to dbClick in some test got exception here
  WaitUtils.sleepQuietly(200, TimeUnit.MILLISECONDS);
  new Actions(seleniumWebDriver).doubleClick(commandTypeElement).perform();
}
 
Example #13
Source File: dragAndDropIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 6 votes vote down vote up
@Test
public void automateJavaScriptDragAndDropWithOffsetsStep4() {
    driver.get("http://web.masteringselenium.com/jsDragAndDropWithHandle.html");
    Actions advancedActions = new Actions(driver);
    final By destroyableBoxes = By.cssSelector("ul > li > div");
    WebElement obliterator = driver.findElement(By.id("obliterate"));
    WebElement firstBox = driver.findElement(By.id("one"));
    WebElement firstBoxText = driver.findElement(By.cssSelector("#one > span"));

    assertThat(driver.findElements(destroyableBoxes).size()).isEqualTo(5);

    CalculateOffsetPosition op =
            new CalculateOffsetPosition(firstBox, firstBoxText, CursorPosition.CENTER);

    advancedActions.moveToElement(firstBox)
            .moveByOffset(op.getXOffset(), op.getYOffset())
            .clickAndHold()
            .moveToElement(obliterator)
            .release()
            .perform();

    assertThat(driver.findElements(destroyableBoxes).size()).isEqualTo(4);
}
 
Example #14
Source File: Basic.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Action(object = ObjectType.SELENIUM,
        desc = "Move the Browser View to the specified element [<Object>]")
public void moveTo() {
    if (elementDisplayed()) {
        if (Data != null && Data.matches("(\\d)+,(\\d)+")) {
            int x = Integer.valueOf(Data.split(",")[0]);
            int y = Integer.valueOf(Data.split(",")[1]);
            new Actions(Driver).moveToElement(Element, x, y).build().perform();
        } else {
            new Actions(Driver).moveToElement(Element).build().perform();
        }
        Report.updateTestLog(Action, "Viewport moved to" + ObjectName, Status.DONE);
    } else {
        throw new ElementException(ExceptionType.Element_Not_Visible, ObjectName);
    }
}
 
Example #15
Source File: JMenuTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void checkBoxMenuItemClick() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));
    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("check-box-menu-item"));
    int i = menuItems.size();
    assertMenuItemClick(menuItems, --i,
            "Event source: Another one (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    WebElement currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));

    new Actions(driver).moveToElement(menu).click().perform();
    assertMenuItemClick(menuItems, --i,
            "Event source: A check box menu item (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));
}
 
Example #16
Source File: WebdriverModule.java    From bobcat with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  Multibinder.newSetBinder(binder(), WebDriverEventListener.class);

  Multibinder<WebDriverClosedListener> closedListeners = Multibinder
      .newSetBinder(binder(), WebDriverClosedListener.class);
  closedListeners.addBinding().to(FrameSwitcher.class);
  closedListeners.addBinding().to(ProxyCloser.class);

  install(new FactoryModuleBuilder()
      .implement(ClosingAwareWebDriver.class, ClosingAwareWebDriverWrapper.class)
      .build(ClosingAwareWebDriverFactory.class));

  bind(WebDriver.class).toProvider(WebDriverProvider.class);
  bind(Actions.class).toProvider(ActionsProvider.class);
  bind(Capabilities.class).toProvider(CapabilitiesProvider.class);
  bind(JavascriptExecutor.class).toProvider(JavascriptExecutorProvider.class);
}
 
Example #17
Source File: SiteToolbarImpl.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Override
public void createPage(String template, String title, String name) {
  Actions actions = new Actions(webDriver);
  actions.pause(2000).perform();
  createButton.click();
  currentScope
      .findElement(By.className("cq-siteadmin-admin-create" + StringUtils.lowerCase("page")))
      .click();
  createPageWizard.selectTemplate(template).provideTitle(title).provideName(name).submit();
}
 
Example #18
Source File: SiteToolbarImpl.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Override
public void createPage(String template, String title, String name) {
  Actions actions = new Actions(webDriver);
  actions.pause(2000).perform();
  createButton.click();
  currentScope
      .findElement(By.className("cq-siteadmin-admin-create" + StringUtils.lowerCase("page")))
      .click();
  createPageWizard.selectTemplate(template).provideTitle(title).provideName(name).submit();
}
 
Example #19
Source File: ClientAddPage.java    From oxTrust with MIT License 5 votes vote down vote up
public void selectTab(String tabName) {
	scrollUp();
	scrollUp();
	WebElement main = webDriver.findElement(By.className(BOX_HEADER));
	WebElement tab = main.findElement(By.className(tabName));
	Actions action = new Actions(webDriver);
	action.click(tab);
	action.build().perform();
}
 
Example #20
Source File: ProjectExplorer.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Performs the multi-select by {@code Shift} key with check selected items, for items between
 * {@code firstItemPath} and {@code secondItemPath} including this two items.
 *
 * @param firstItemPath is the path to the first item which will be clicked in format:
 *     "Test/src/pom.xml".
 * @param secondItemPath is the path to the second item which will be clicked in format:
 *     "Test/src/pom.xml".
 * @param selectedItemsPaths is the paths to the each items which should be checked.
 */
public void selectMultiFilesByShiftKeyWithCheckMultiselection(
    String firstItemPath, String secondItemPath, List<String> selectedItemsPaths) {
  waitAndSelectItem(firstItemPath);
  waitItemIsSelected(firstItemPath);

  Actions actions = actionsFactory.createAction(seleniumWebDriver);
  actions.keyDown(SHIFT).perform();
  waitAndSelectItem(secondItemPath);
  waitAllItemsIsSelected(selectedItemsPaths);
  actions.keyUp(SHIFT).perform();
}
 
Example #21
Source File: WebDriverElement.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Drag this element and drop onto another element.
 * 
 * @param dropControl
 *            target of the drag and drop
 */
public void dragNDrop(WebDriverElement dropControl)
		throws CandybeanException {
	logger.info("Dragging element: " + this.toString()
			+ " to element: " + dropControl.toString());
	Actions action = new Actions(this.wd);
	action.dragAndDrop(this.we, dropControl.we).build().perform();
}
 
Example #22
Source File: NativeEventsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override
        public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example #23
Source File: DriverHelper.java    From carina with Apache License 2.0 5 votes vote down vote up
/**
  * Performs slider move for specified offset.
  * 
  * @param slider
  *            slider
  * @param moveX
  *            move x
  * @param moveY
  *            move y
  */
 public void slide(ExtendedWebElement slider, int moveX, int moveY) {
 	//TODO: SZ migrate to FluentWaits
     if (slider.isElementPresent()) {
         WebDriver drv = getDriver();
         (new Actions(drv)).moveToElement(slider.getElement()).dragAndDropBy(slider.getElement(), moveX, moveY)
                 .build().perform();
Messager.SLIDER_MOVED.info(slider.getNameWithLocator(), String.valueOf(moveX), String.valueOf(moveY));
     } else {
         Messager.SLIDER_NOT_MOVED.error(slider.getNameWithLocator(), String.valueOf(moveX), String.valueOf(moveY));
     }
 }
 
Example #24
Source File: CommandsExplorer.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * select command and open in editor
 *
 * @param commandName is a visible command name in command explorer
 */
public void selectCommandByName(String commandName) {
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOf(getCommandByName(commandName)));
  new Actions(seleniumWebDriver).doubleClick(getCommandByName(commandName)).build().perform();
  waitCommandIsSelected(commandName);
}
 
Example #25
Source File: HtmlSelect2Test.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({"false", "true", "true", "true"})
@BuggyWebDriver(IE = {"false", "false", "true", "false"})
public void shiftClick() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n"
        + "<form id='form1'><select name='select1' multiple>\n"
        + "  <option value='option1'>Option1</option>\n"
        + "  <option value='option2'>Option2</option>\n"
        + "  <option value='option3' selected='selected'>Option3</option>\n"
        + "  <option value='option4'>Option4</option>\n"
        + "</select>\n"
        + "<input type='submit' name='button' value='foo'/>\n"
        + "</form></body></html>";

    final WebDriver driver = loadPage2(html);

    final List<WebElement> options = driver.findElements(By.tagName("option"));

    final Actions actions = new Actions(driver);
    final Action selectThreeOptions = actions.click(options.get(1))
            .keyDown(Keys.SHIFT)
            .click(options.get(3))
            .keyUp(Keys.SHIFT)
            .build();

    selectThreeOptions.perform();

    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), options.get(0).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), options.get(1).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), options.get(2).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[3]), options.get(3).isSelected());
}
 
Example #26
Source File: ClickableElement2Test.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("click click dblclick ")
public void dblClick() throws Exception {
    final String content = "<html>\n"
        + "<head>\n"
        + "<script>\n"
        + "  function clickMe() {\n"
        + "    document.getElementById('myTextarea').value+='click ';\n"
        + "  }\n"
        + "  function dblClickMe() {\n"
        + "    document.getElementById('myTextarea').value+='dblclick ';\n"
        + "  }\n"
        + "</script>\n"
        + "</head>\n"
        + "<body id='myBody' onclick='clickMe()' ondblclick='dblClickMe()'>\n"
        + "<textarea id='myTextarea'></textarea>\n"
        + "</body></html>";

    final WebDriver driver = loadPage2(content);

    final Actions action = new Actions(driver);
    action.doubleClick(driver.findElement(By.id("myBody")));
    action.perform();

    assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("myTextarea")).getAttribute("value"));
}
 
Example #27
Source File: UserUpdatePage.java    From oxTrust with MIT License 5 votes vote down vote up
public void delete() {
	scrollDown();
	WebElement button = webDriver.findElement(By.className("deletePersonButton"));
	Actions actions = new Actions(webDriver);
	actions.moveToElement(button).click().perform();
	fluentWait(ONE_SEC);
	WebElement dialog = webDriver.findElement(By.id("deleteConfirmation:acceptRemovalModalPanel_content"));
	dialog.findElements(By.tagName("input")).get(0).click();
	fluentWait(ONE_SEC);
}
 
Example #28
Source File: CommandsExplorer.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
public void runCommandByName(String commandName) {
  new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC)
      .until(ExpectedConditions.visibilityOf(getCommandByName(commandName)));
  new Actions(seleniumWebDriver).doubleClick(getCommandByName(commandName)).build().perform();
  commandsEditor.waitActive();
  commandsEditor.clickOnRunButton();
  commandsEditor.clickOnCancelCommandEditorButton();
}
 
Example #29
Source File: HTMLElement2Test.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts({"clicked", "fireEvent not available"})
public void fireEvent_WithoutTemplate() throws Exception {
    final String html =
        "<html>\n"
        + "  <head>\n"
        + "    <title>Test</title>\n"
        + "    <script>\n"
        + "    function doTest() {\n"
        + "      var elem = document.getElementById('a');\n"
        + "      if (!elem.fireEvent) { alert('fireEvent not available'); return }\n"
        + "      elem.fireEvent('onclick');\n"
        + "    }\n"
        + "    </script>\n"
        + "  </head>\n"
        + "<body>\n"
        + "  <div id='a' onclick='alert(\"clicked\")'>foo</div>\n"
        + "  <div id='b' onmouseover='doTest()'>bar</div>\n"
        + "</body></html>";

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("a")).click();
    verifyAlerts(driver, getExpectedAlerts()[0]);

    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("b")));
    actions.perform();
    verifyAlerts(driver, getExpectedAlerts()[1]);
}
 
Example #30
Source File: FindText.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** launch the 'Find' main form by keyboard */
public void launchFindFormByKeyboard() {
  loader.waitOnClosed();
  Actions action = actionsFactory.createAction(seleniumWebDriver);
  action
      .keyDown(Keys.CONTROL)
      .keyDown(Keys.SHIFT)
      .sendKeys("f")
      .keyUp(Keys.SHIFT)
      .keyUp(Keys.CONTROL)
      .perform();
}