Java Code Examples for org.openqa.selenium.interactions.Actions

The following are top voted examples for showing how to use org.openqa.selenium.interactions.Actions. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: vaadin   File: WindowElement.java View source code 14 votes vote down vote up
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();
}
 
Example 2
Project: richfaces   File: TextInputComponentImpl.java View source code 9 votes vote down vote up
public TextInputComponentImpl clear(ClearType clearType) {
    int valueLength = root.getAttribute("value").length();
    Actions builder = new Actions(driver);
    switch (clearType) {
        case BACKSPACE:
            for (int i = 0; i < valueLength; i++) {
            builder.sendKeys(root, Keys.BACK_SPACE);
        }
            builder.build().perform();
            break;
        case DELETE:
            String ctrlADel = Keys.chord(Keys.CONTROL, "a", Keys.DELETE);
            builder.sendKeys(root, ctrlADel);
            builder.build().perform();
            break;
        case ESCAPE_SQ:
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < valueLength; i++) {
                sb.append("\b");
            }
            root.sendKeys(sb.toString());
            root.click();
            break;
        case JS:
            Utils.jQ(executor, "val('')", root);
            break;
        case WD:
            root.clear();
            break;
        default:
            throw new UnsupportedOperationException("Unknown type of clear method " + clearType);
    }
    return TextInputComponentImpl.this;
}
 
Example 3
Project: richfaces   File: RichFacesInputNumberSlider.java View source code 9 votes vote down vote up
public void dragHandleToPointInTrace(int pixelInTrace) {
    Preconditions.checkArgument(pixelInTrace >= 0 && pixelInTrace <= getWidth(),
        "Cannot slide outside the trace.");
    if (!Utils.isVisible(advanced().getRootElement())) {
        throw new RuntimeException("Trace is not visible.");
    }
    scrollToView();
    // clickAndHold(element) replaced by moveToElement with offset + clickAndHold (RF-14183)
    Actions actions = new Actions(browser).moveToElement(advanced().getHandleElement(), 0, 0).clickAndHold();
    actions.moveToElement(advanced().getRootElement(), pixelInTrace, 0);
    actions.release(advanced().getHandleElement()).build().perform();
}
 
Example 4
Project: kune   File: SeleniumUtils.java View source code 6 votes vote down vote up
/**
 * Move mouse to.
 * 
 * @param webdriver
 *          the webdriver
 * @param element
 *          the element
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 */
public static void moveMouseTo(final WebDriver webdriver, final WebElement element, final int xOffset,
    final int yOffset) {
  showCursor(webdriver, element, xOffset, yOffset);
  final Actions actions = new Actions(webdriver);
  actions.moveToElement(element, xOffset, yOffset);
  final Action action = actions.build();
  action.perform();
}
 
Example 5
Project: SeleniumDemos   File: ActionClassInWebDriver.java View source code 5 votes vote down vote up
/**
 * @param args
 * @throws InterruptedException 
 */

public static void main(String[] args) throws InterruptedException {
	// TODO Auto-generated method stub
	WebDriver driver = new FirefoxDriver();
	driver.get("http://www.nokia.indiatimes.com");
	driver.manage().window().maximize();
	
	
	Actions actions = new Actions(driver);
	WebElement imageSpan = driver.findElement(By.cssSelector(".FancytoolTip.combooffer>a"));
	actions.moveToElement(imageSpan);

	actions.perform();
	Thread.sleep(1000);
	/*WebElement subLink = driver.findElement(By.cssSelector(".FancytoolTip.combooffer>a"));
	actions.moveToElement(subLink);
	actions.click();
	actions.perform();*/


}
 
Example 6
Project: rstudio   File: RConsoleInteraction.java View source code 5 votes vote down vote up
@Test
public void testBasicRInteraction() {
    Actions do42 = new Actions(driver_);
    do42.sendKeys(Keys.chord(Keys.CONTROL, "l"));
    do42.sendKeys(Keys.ESCAPE);
    do42.sendKeys("41 + 1");
    do42.sendKeys(Keys.ENTER);
    do42.perform();

    ConsoleTestUtils.waitForConsoleContainsText(driver_, "42");
}
 
Example 7
Project: qxwebdriver-java   File: TableIT.java View source code 5 votes vote down vote up
@Test
public void editCell() throws InterruptedException {
	String browserName = System.getProperty("org.qooxdoo.demo.browsername");
	String browserVersion = System.getProperty("org.qooxdoo.demo.browserversion");
	boolean condition = browserName.contains("internet") && browserVersion.equals("8");
	org.junit.Assume.assumeTrue(!condition);
	String cellXpath = "div[contains(@class, 'qooxdoo-table-cell') and position() = 3]";
	String newText = "Hello WebDriver!";
	
	// Scroll to row #12 and select cell #3
	WebElement row = table.scrollToRow(12);
	WebElement dateCell = row.findElement(By.xpath(cellXpath));
	dateCell.click();
	
	// Double click cell #3 to activate edit mode
	Actions builder = new Actions(driver.getWebDriver());
	builder.doubleClick(dateCell).perform();

	Widget editor = table.getCellEditor();
	String old = (String) editor.getPropertyValue("value");
	
	// Clear old content
	Actions keyBuilder = new Actions(driver.getWebDriver())
		.sendKeys(Keys.END);
	for (int i = 0; i < old.length(); i++) {
		keyBuilder.sendKeys(Keys.BACK_SPACE);
	}
	keyBuilder.perform();
	
	// Type new cell content
	editor.sendKeys(newText);
	editor.sendKeys(Keys.RETURN);
	
	// update the cell element and check the new content
	row = table.scrollToRow(12);
	dateCell = row.findElement(By.xpath(cellXpath));
	Assert.assertEquals(newText,  dateCell.getText());
}
 
Example 8
Project: seleniumcapsules   File: DragAndDropTest.java View source code 5 votes vote down vote up
@Test
public void autoCompeleteUsingSelenium() throws InterruptedException {
    FirefoxBinary binary = new FirefoxBinary(new File("src/main/resources/Firefox/Contents/MacOS/firefox-bin"));
    FirefoxProfile profile = new FirefoxProfile(new File("src/main/resources/Firefox/Profiles/default"));
    WebDriver driver = new FirefoxDriver(binary, profile);
    driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
    WebElement source = driver.findElement(id("drag1"));
    System.out.println(source.getAttribute("src"));
    WebElement target = driver.findElement(id("div2"));
    System.out.println(target.getTagName() + "=" + target.toString());
    Actions actions = new Actions(driver);
    actions.dragAndDrop(source, target);
    actions.perform();
}
 
Example 9
Project: AisAbnormal   File: StatisticDataIT.java View source code 5 votes vote down vote up
private void clickOnACell() throws InterruptedException {
    zoomIntoHelsinore();
    waitForCellsToBeDisplayed();

    WebElement map = getMap();

    Actions actions = new Actions(browser);
    actions.moveToElement(map, map.getSize().getWidth() / 2, map.getSize().getHeight() / 2);
    actions.click();
    actions.perform();

    // Cursor position is exactly in the center of the map
    browser.findElement(By.id("tab-map")).click();
    assertEquals("(56°02'05.7\"N, 12°38'59.7\"E)", browser.findElement(By.cssSelector("div#cursorpos.useroutput p")).getText());

    // Assert statistic data for correct cell displayed
    final String expectedCellInfo = "Cell id 6249302540 (56°02'06.5\"N,12°38'53.8\"E) - (56°02'00\"N,12°39'00.3\"E)";
    By actualCellInfoElement = By.cssSelector("div.cell-data-contents > h5");
    wait.until(ExpectedConditions.textToBePresentInElement(actualCellInfoElement, expectedCellInfo));
}
 
Example 10
Project: arquillian-graphene   File: TestInitializingPageFragments.java View source code 5 votes vote down vote up
@Test
public void testSupportForAdvancedActions() {
    Actions builder = new Actions(selenium);

    // following tests usage of Actions with injected plain WebElement
    builder.click(input);
    // following with List<WebElement>
    builder.click(divs.get(0));
    // following with WebElements from Page Fragments
    builder.click(abstractPageFragmentStub.getLocatorRefByXPath());
    // following with List of WebElements from Page Fragments
    builder.click(abstractPageFragmentStub.getSpansInPageFragment().get(0));

    builder.perform();
}
 
Example 11
Project: gxt-driver   File: TreeDndTest.java View source code 5 votes vote down vote up
@Test
public void testDragAndDrop() {
	Tree t = new Tree(driver, driver.findElement(new ByChained(By.xpath("//body/*"), new ByWidget(driver, com.sencha.gxt.widget.core.client.tree.Tree.class))));

	Item root = t.findItemWithText("root");
	root.toggleExpand();
	Assert.assertEquals(2, root.getChildren().size());

	Item foo = root.getChildren().get(0);
	foo.toggleExpand();

	Item bar = foo.getChildren().get(0);
	foo.getElement();
	Actions a = new Actions(driver);
	a.clickAndHold(bar.getElement());
	a.moveToElement(root.getElement());
	a.release();

	a.perform();

	Assert.assertEquals(3, root.getChildren().size());

}
 
Example 12
Project: grafaces   File: PuiAutocomplete.java View source code 5 votes vote down vote up
public void sendKeys(Keys... keys) {
    Actions builder = new Actions(driver);
    for (Keys key : keys) {
        builder.sendKeys(key);
    }
    builder.build().perform();
}
 
Example 13
Project: rstudio   File: RConsoleInteraction.java View source code 5 votes vote down vote up
@Test
public void testPlotGeneration() {
   ConsoleTestUtils.resumeConsoleInteraction(driver_);

   Actions plotCars = new Actions(driver_);
   plotCars.sendKeys(Keys.ESCAPE + "plot(cars)" + Keys.ENTER);
   plotCars.perform();
   
   // Wait for the Plot window to activate
   final WebElement plotWindow = (new WebDriverWait(driver_, 5))
     .until(ExpectedConditions.presenceOfElementLocated(
           By.id(ElementIds.getElementId(ElementIds.PLOT_IMAGE_FRAME))));
   
   // Wait for a plot to appear in the window
   Assert.assertEquals(plotWindow.getTagName(), "iframe");
   driver_.switchTo().frame(plotWindow);

   (new WebDriverWait(driver_, 5))
     .until(ExpectedConditions.presenceOfElementLocated(By.tagName("img")));
   
   // Switch back to document context
   driver_.switchTo().defaultContent();
}
 
Example 14
Project: vaadin   File: CurrentTimeMillisTest.java View source code 5 votes vote down vote up
private String getJsonParsingTime() {
    Actions actions = new Actions(getDriver());
    actions.sendKeys(Keys.TAB);
    actions.sendKeys(Keys.SPACE).perform();
    findElement(By.className("v-debugwindow-tab")).click();

    List<WebElement> messages = findElements(By
            .className("v-debugwindow-message"));
    for (WebElement message : messages) {
        if (message.getAttribute("innerHTML").startsWith("JSON parsing")) {
            String text = message.getAttribute("innerHTML");
            int index = text.lastIndexOf(' ');
            return text.substring(index);
        }
    }
    return null;
}
 
Example 15
Project: vaadin   File: PushVersionInfoTest.java View source code 5 votes vote down vote up
private void selectInfoTab() {
    if (isElementPresent(By.className("v-ie8"))) {

        int size = findElements(By.className("v-debugwindow-tab")).size();
        for (int i = 0; i < size; i++) {
            WebElement tab = findElement(By
                    .className("v-debugwindow-tab-selected"));
            String title = tab.getAttribute("title");
            if (title != null && title.startsWith("General information")) {
                break;
            }
            Actions actions = new Actions(getDriver());
            actions.sendKeys(Keys.TAB);
            actions.sendKeys(Keys.SPACE);
            actions.build().perform();
        }
    } else {
        findElements(By.className("v-debugwindow-tab")).get(0).click();
        findElements(By.className("v-debugwindow-tab")).get(1).click();
    }
}
 
Example 16
Project: uberfire   File: DragAndDropTest.java View source code 5 votes vote down vote up
@Test
public void dragCompassShouldBeCenteredOverRootListTargetPanel() throws Exception {
    WebElement listDragHandle = driver.findElement( By.id( "gwt-debug-" + ListBarWidget.DEBUG_TITLE_PREFIX + "DnD-2" ) );

    // make sure we're grabbing the right thing
    assertEquals( "DnD-2", listDragHandle.getText() );

    // get the compass to appear over the root panel (which is a MultiList panel)
    WebElement listPanel = driver.findElement( By.id( "DragAndDropPerspective-list" ) );
    Actions dragAndDrop = new Actions( driver );
    dragAndDrop.clickAndHold( listDragHandle );
    dragAndDrop.moveToElement( listPanel );
    dragAndDrop.perform();

    // now find the south point of the compass and drop on it
    WebElement compassCenter = driver.findElement( By.id( "gwt-debug-CompassWidget-centre" ) );
    assertCentered( listPanel, compassCenter );
}
 
Example 17
Project: richfaces-qa   File: TestPanelMenuDOMEvents.java View source code 5 votes vote down vote up
@Test
@CoversAttributes("onmouseover")
@Templates("plain")
public void testOnmouseover() {
    //This test should be done first, because use static x and y variables
    Actions mouseover = new Actions(driver).moveToElement(getPage().getRequestTimeElement());
    mouseover.moveToElement(getPage().getPanelMenu().advanced().getRootElement(), 3, 3);
    testFireEvent(panelMenuAttributes, onmouseover, mouseover.build());
}
 
Example 18
Project: senbot   File: NavigationService.java View source code 5 votes vote down vote up
/**
 * Hovers the mouse over the given element
 * @param locator The element locator
 */
public void mouseHoverOverElement(By locator) {
    SynchronisationService synchronisationService = new SynchronisationService();

    synchronisationService.waitAndAssertForExpectedCondition(ExpectedConditions.visibilityOfElementLocated(locator));

    WebElement element = getWebDriver().findElement(locator);
    Actions builder = new Actions(getWebDriver());
    Actions hoverOverRegistrar = builder.moveToElement(element);
    hoverOverRegistrar.perform();
}
 
Example 19
Project: PhenotypeArchive   File: SearchGeneTable.java View source code 5 votes vote down vote up
public GeneDetails(WebElement geneColElement) {        
    
    // In order to see the contents of the span, we need to first bring
    // the gene symbol into view, then hover over it.
    Actions builder = new Actions(driver);

    try {
        TestUtils.scrollToTop(driver, geneColElement, -50);             // Scroll gene symbol into view.
        Actions hoverOverGene = builder.moveToElement(geneColElement);
        hoverOverGene.perform();                                        // Hover over the gene symbol.
        
        List<WebElement> humanOrthologElements = geneColElement.findElements(By.cssSelector("div.subinfo ul.ortholog li"));
        if ( ! humanOrthologElements.isEmpty()) {
            for (WebElement humanOrthologElement : humanOrthologElements) {
                humanOrthologs.add(humanOrthologElement.getText());
            }
        } else {
            String[] rawHumanOrthologStrings = geneColElement.findElement(By.cssSelector("div.subinfo")).getText().split("\n");
            for (String humanOrthologString : rawHumanOrthologStrings) {
                String[] humanOrthologParts = humanOrthologString.split(":");
                if (humanOrthologParts[0].trim().equals("human ortholog")) {
                    humanOrthologs.add(humanOrthologParts[1].trim());
                    break;
                }
            }
        }

        String subinfoDivText = geneColElement.getText();
        String[] subinfoDivLines = subinfoDivText.split("\n");
        for (String subinfoDivLine : subinfoDivLines) {
            String[] textParts = subinfoDivLine.split(":");
            switch (textParts[0].trim().toLowerCase()) {
                case "name":
                    this.name = textParts[1].trim();                    // geneName.
                    break;
                    
                default:
                    break;
            }
         }
    } catch (Exception e) {
        System.out.println("EXCEPTION: SearchGeneTable.GeneDetails.GeneDetails() while waiting to hover. Error message: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
}
 
Example 20
Project: powersweeper   File: ScreenGameInterface.java View source code 5 votes vote down vote up
/**
 * Builds a tile related browser action.
 *
 * @param x The X-Coordinate.
 * @param y The Y-Coordinate.
 * @return The action.
 */
public Actions buildTileAction(short x, short y) {
    // create action
    Actions action = new Actions(this.powersweeper.getDriverManager().getDriver());

    // find HTML element
    WebElement html = this.powersweeper.getDriverManager().getDriver().findElement(By.tagName("html"));

    // get real coordinate
    int realX = this.getRealCoordinate(x);
    int realY = this.getRealCoordinate(y);

    realX += (CELL_SIZE / 2);
    realY += (CELL_SIZE / 2);

    // move cursor
    action.moveToElement(html, realX, realY);

    // return action
    return action;
}
 
Example 21
Project: spreadsheet   File: MultipleSheetTest.java View source code 4 votes vote down vote up
@Test
public void testRenameSheet() {
    skipBrowser("Cannot find the 'new sheet name' element on PhantomJS", Browser.PHANTOMJS);

    createNewSheet();
    Actions actions = new Actions(driver);
    actions.doubleClick(driver.findElement(By
            .xpath("//div[@class='sheet-tabsheet-container']//div[text()='Sheet1']")));
    actions.perform();
    testBench(driver).waitForVaadin();
    driver.findElement(
            By.cssSelector(".sheet-tabsheet-tab.selected-tab input"))
            .clear();
    driver.findElement(
            By.cssSelector(".sheet-tabsheet-tab.selected-tab input"))
            .click();
    // driver.findElement(By.xpath("//*[@class='sheet-tabsheet-container']//input")).click();
    // driver.findElement(
    // By.xpath("//*[@class='sheet-tabsheet-container']//input"))
    driver.findElement(
            By.cssSelector(".sheet-tabsheet-tab.selected-tab input"))
            .sendKeys(
                    Keys.chord(Keys.CONTROL, Keys.DELETE)
                            + "new sheet name" + Keys.RETURN);
    testBench(driver).waitForVaadin();
    driver.findElement(By
            .xpath("//*[@class='sheet-tabsheet-container']//*[text()='new sheet name']"));
    loadServerFixture("SHEET_RENAME_1");
    Assert.assertNotNull(driver.findElement(By
            .xpath("//*[@class='sheet-tabsheet-container']//*[text()='new_sheet_REnamed']")));
}
 
Example 22
Project: uberfire   File: DragAndDropTest.java View source code 4 votes vote down vote up
@Test
public void testDragFromListPanelToSouthOfSelf() throws Exception {
    WebElement listDragHandle = driver.findElement( By.id( "gwt-debug-" + ListBarWidget.DEBUG_TITLE_PREFIX + "DnD-2" ) );

    // make sure we're grabbing the right thing
    assertEquals( "DnD-2", listDragHandle.getText() );

    // get the compass to appear
    Actions dragAndDrop = new Actions( driver );
    dragAndDrop.clickAndHold( listDragHandle );
    dragAndDrop.moveByOffset( 0, 50 );
    dragAndDrop.perform();

    // now find the south point of the compass and drop on it
    WebElement compassSouth = driver.findElement( By.id( "gwt-debug-CompassWidget-south" ) );
    dragAndDrop.click( compassSouth );
    dragAndDrop.perform();

    // The DnD-1 screen should have appeared now to take the place of DnD-2, which we have moved away
    WebElement dnd1Screen = driver.findElement( By.id( "DragAndDropScreen-1" ) );
    WebElement dnd2Screen = driver.findElement( By.id( "DragAndDropScreen-2" ) );

    // to prove it worked, we should ensure DnD-2 is south of DnD-1
    assertTrue( dnd1Screen.isDisplayed() );
    assertRelativePosition( CompassPosition.SOUTH, dnd1Screen, dnd2Screen );
}