Example usage for org.openqa.selenium WebElement submit

List of usage examples for org.openqa.selenium WebElement submit

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement submit.

Prototype

void submit();

Source Link

Document

If this current element is a form, or an element within a form, then this will be submitted to the remote server.

Usage

From source file:org.mitre.mpf.wfm.ui.LoginPage.java

License:Open Source License

/**
 * Login as valid user/*from   ww w  .  j  a  v a 2 s .  c om*/
 *
 * @param userName
 * @param password
 * @return HomePage object
 */
public HomePage loginValidUser(WebDriver driver, String username, String password) {

    WebElement element = driver.findElement(By.name("username"));
    element.sendKeys(username);
    element = driver.findElement(By.name("password"));
    element.sendKeys(password);
    // Now submit the form.
    element.submit();

    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().startsWith(HomePage.PAGE_TITLE);
        }
    });

    return new HomePage(driver);
}

From source file:org.mule.modules.selenium.SeleniumModule.java

License:Open Source License

/**
 * If the element at the payload is a form, or an element within a form, then this will be submitted to
 * the remote server. If this causes the current page to change, then this method will block until
 * the new page is loaded.// w  w w .  j a v a2s.c  om
 * <p/>
 * {@sample.xml ../../../doc/mule-module-selenium.xml.sample selenium:submit}
 *
 * @param element Element located at the payload of the message
 * @throws {@link java.util.NoSuchElementException} If the given element is not within a form
 */
@Processor
public void submit(@Payload WebElement element) {
    element.submit();
}

From source file:org.netbeans.modules.jackpot30.web.ui.test.OverallTest.java

License:Open Source License

@Test
public void overallTest() throws Exception {
    //        WebDriver driver = new FirefoxDriver();
    WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_10);

    ((HtmlUnitDriver) driver).setJavascriptEnabled(true);

    try {/*  w w w . jav  a2s .  c o m*/
        driver.get("http://localhost:" + System.getProperty("PORT", "9998") + "/index/ui/index.html");

        //wait for the page to be rendered:
        new WebDriverWait(driver, 20).until(new Predicate<WebDriver>() {
            public boolean apply(WebDriver t) {
                List<WebElement> cb = t.findElements(By.id("projectCheckBox-data"));
                return !cb.isEmpty() && cb.get(0).isDisplayed();
            }
        });

        WebElement searchInput = driver.findElements(By.id("search-input")).get(0);

        searchInput.sendKeys("ClassA");
        searchInput.submit();

        WebElement link = new WebDriverWait(driver, 20).until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver t) {
                List<WebElement> cb = t.findElements(By.tagName("a"));

                for (WebElement we : cb) {
                    String href = we.getAttribute("href");

                    if (href != null
                            && href.contains("goto=CLASS:org.netbeans.modules.jackpot30.example.ClassA"))
                        return we;
                }

                return null;
            }
        });

        link.click();

        WebElement methodIdentifierSpan = new WebDriverWait(driver, 20)
                .until(new Function<WebDriver, WebElement>() {
                    public WebElement apply(WebDriver t) {
                        List<WebElement> cb = t.findElements(By.tagName("span"));

                        for (WebElement we : cb) {
                            String href = we.getAttribute("jpt30pos");

                            if (href != null && href.equals("88"))
                                return we;
                        }

                        return null;
                    }
                });

        String classes = methodIdentifierSpan.getAttribute("class");

        Assert.assertTrue(classes.contains("identifier") && classes.contains("method")
                && classes.contains("declaration") && classes.contains("public"));

        methodIdentifierSpan.click();

        Assert.assertEquals(
                Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java",
                        "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"),
                usagesList(driver));

        findCheckbox(driver, "showUsages").click(); //uncheck

        Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java"),
                usagesList(driver));

        findCheckbox(driver, "showUsages").click(); //check

        Assert.assertEquals(
                Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java",
                        "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"),
                usagesList(driver));

        findCheckbox(driver, "showSubtypes").click(); //uncheck

        Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"),
                usagesList(driver));

        findCheckbox(driver, "showSubtypes").click(); //uncheck

        Assert.assertEquals(
                Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java",
                        "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"),
                usagesList(driver));
    } finally {
        driver.quit();
    }
}

From source file:org.opencastproject.loadtest.engage.LoadTestEngage.java

License:Educational Community License

/**
 * If opening a page results in a log in page this will authenticate against it. 
 *//*from  w  w  w.ja v  a2s  . c om*/
private void authenticate() {
    logger.debug(name + "-Login title is: " + driver.getTitle());
    WebElement username = driver.findElement(By.name(guiSettings.getUsernameFieldName()));
    username.sendKeys(guiSettings.getUsername());
    WebElement password = driver.findElement(By.name(guiSettings.getPasswordFieldName()));
    password.sendKeys(guiSettings.getPassword());
    password.submit();
}

From source file:org.openlmis.functional.ChromeTest.java

License:Open Source License

@Test
public void testGoogleSearch() {
    // Optional, if not specified, WebDriver will search your path for chromedriver.
    System.setProperty("webdriver.chrome.driver", "/home/mesh/Programs/chromedriver");

    WebDriver driver = new ChromeDriver();
    driver.get("http://www.google.com/xhtml");

    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("ChromeDriver");
    searchBox.submit();
    driver.quit();//w w w. j  a v a  2  s .c om
}

From source file:org.opennms.smoketest.ProvisioningIT.java

License:Open Source License

@Test
public void testRequisitionUI() throws Exception {
    final WebElement form = waitForElement(By.xpath("//form[@name='takeAction']"));
    form.findElement(By.cssSelector("input[type=text][name=groupName]")).click();
    form.findElement(By.cssSelector("input[type=text][name=groupName]")).sendKeys(REQUISITION_NAME);
    form.submit();

    // edit the foreign source
    findElementById("edit_fs_anchor_" + REQUISITION_NAME).click();

    // add a detector
    waitForElement(By.xpath("//input[@value='Add Detector']")).click();
    String detectorNode = setTreeFieldsAndSave("foreignSourceEditForm", type("name", "HTTP-8980"),
            select("pluginClass", "HTTP"));

    // set the port to 8980
    waitForElement(By.xpath("//a[contains(@href, '" + detectorNode + "') and text() = '[Add Parameter]']"))
            .click();// w ww . j  a v  a2 s. co m
    setTreeFieldsAndSave("foreignSourceEditForm", select("key", "port"), type("value", "8980"));

    waitForElement(By.xpath("//input[@value='Done']")).click();

    // add a node
    findElementById("edit_req_anchor_" + REQUISITION_NAME).click();
    waitForElement(By.xpath("//input[@value='Add Node']")).click();
    String nodeForNode = setTreeFieldsAndSave("nodeEditForm", type("nodeLabel", NODE_LABEL),
            type("foreignId", NODE_LABEL));

    // add the node interface
    waitForElement(By.xpath("//a[contains(@href, '" + nodeForNode + "') and text() = '[Add Interface]']"))
            .click();
    setTreeFieldsAndSave("nodeEditForm", type("ipAddr", "::1"));

    // add the interface service
    waitForElement(By.xpath("//a[text() = 'Add Service']")).click();
    setTreeFieldsAndSave("nodeEditForm", select("serviceName", "HTTP-8980"));

    waitForElement(By.xpath("//input[@value='Done']")).click();
    waitForElement(By.xpath("//input[@value='Synchronize']")).click();

    assertTrue(wait.until(new WaitForNodesInDatabase(1)));
    LOG.debug("Found 1 node in the database.");

    // wait for the node scanning to complete
    Thread.sleep(5000);

    m_driver.get(getBaseUrl() + "opennms/element/node.jsp?node=" + REQUISITION_NAME + ":" + NODE_LABEL);
    waitForElement(By.xpath("//h3[text()='Availability']"));

    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("ICMP")));
    waitForElement(By.xpath("//a[contains(@href, 'element/interface.jsp') and text()='"
            + InetAddressUtils.normalize("::1") + "']"));
}

From source file:org.opennms.smoketest.ProvisioningTest.java

License:Open Source License

@Test
public void testRequisitionUI() throws Exception {
    final WebElement form = findElementByXpath("//form[@name='takeAction']");
    form.findElement(By.cssSelector("input[type=text][name=groupName]")).sendKeys(REQUISITION_NAME);
    form.submit();

    // edit the foreign source
    findElementById("edit_fs_anchor_" + REQUISITION_NAME).click();

    // add a detector
    findElementByXpath("//input[@value='Add Detector']").click();
    String detectorNode = setTreeFieldsAndSave("foreignSourceEditForm", type("name", "HTTP-8980"),
            select("pluginClass", "HTTP"));

    // set the port to 8980
    findElementByXpath("//a[contains(@href, '" + detectorNode + "') and text() = '[Add Parameter]']").click();
    setTreeFieldsAndSave("foreignSourceEditForm", select("key", "port"), type("value", "8980"));

    findElementByXpath("//input[@value='Done']").click();

    // add a node
    findElementById("edit_req_anchor_" + REQUISITION_NAME).click();
    findElementByXpath("//input[@value='Add Node']").click();
    String nodeForNode = setTreeFieldsAndSave("nodeEditForm", type("nodeLabel", NODE_LABEL));

    // add the node interface
    findElementByXpath("//a[contains(@href, '" + nodeForNode + "') and text() = '[Add Interface]']").click();
    setTreeFieldsAndSave("nodeEditForm", type("ipAddr", "::1"));

    // add the interface service
    findElementByXpath("//a[text() = 'Add Service']").click();
    setTreeFieldsAndSave("nodeEditForm", select("serviceName", "HTTP-8980"));

    findElementByXpath("//input[@value='Done']").click();
    findElementByXpath("//input[@value='Synchronize']").click();

    assertTrue(wait.until(new WaitForNodesInDatabase(1)));
    LOG.debug("Found 1 node in the database.");

    clickMenuItem("Info", "Nodes", "element/nodeList.htm");

    try {//from w  w w . ja v a  2  s. c o m
        findElementByXpath("//h3[text()='Availability']");
    } catch (final Exception e) {
        // We should be on the node list page, click through to the node
        findElementByLink(NODE_LABEL).click();
    }

    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("ICMP")));
    findElementByXpath("//a[contains(@href, 'element/interface.jsp') and text()='"
            + InetAddressUtils.normalize("::1") + "']");
}

From source file:org.openqa.selendroid.tests.CopyOfSayHelloWebviewTest.java

License:Apache License

@Test
public void assertThatWebviewSaysHello() throws Exception {
    WebElement button = driver.findElement(By.id("buttonStartWebview"));
    button.click();/*  w  w w. ja  va  2s  .  c  o m*/
    takeScreenShot("Main Activity started.");

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen")));
    driver.switchTo().window("WEBVIEW");

    WebElement inputField = driver.findElement(By.id("name_input"));
    Assert.assertNotNull(inputField);
    inputField.clear();
    inputField.sendKeys("Dominik");
    takeScreenShot("After entering the name of the app user.");
    inputField.submit();
    takeScreenShot("Result of web view: Hello app user.");
}

From source file:org.openqa.selendroid.tests.SayHelloWebviewTest.java

License:Apache License

@Test
public void assertThatWebviewSaysHello() throws Exception {
    WebElement button = driver.findElement(By.linkText("Start Webview"));
    takeScreenShot("Main Activity started.");
    button.click();/*w  w  w  .  j a  va  2s  . c o m*/
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen")));
    driver.switchTo().window("WEBVIEW");

    WebElement inputField = driver.findElement(By.id("name_input"));
    Assert.assertNotNull(inputField);
    inputField.clear();
    inputField.sendKeys("Dominik");
    takeScreenShot("After entering the name of the app user.");
    inputField.submit();
    takeScreenShot("Result of web view: Hello app user.");
}

From source file:org.openqa.selendroid.tests.UserRegistrationTest.java

License:Apache License

private void registerUser(UserDO user) throws Exception {
    WebElement button = driver.findElement(By.id("startUserRegistration"));
    takeScreenShot("Main Activity started.");
    button.click();//from  w  w w  .  j  av  a 2  s  .com

    WebDriverWait wait = new WebDriverWait(driver, 5);
    WebElement inputUsername = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername")));
    inputUsername.sendKeys(user.getUsername());
    driver.findElement(By.id("inputEmail")).sendKeys(user.getEmail());
    driver.findElement(By.id("inputPassword")).sendKeys(user.getPassword());
    WebElement nameInput = driver.findElement(By.id("inputName"));
    Assert.assertEquals(nameInput.getText(), "Mr. Burns");
    nameInput.clear();
    try {
        nameInput.submit();
        Assert.fail("submit is not supported by SelendroidNativeDriver");
    } catch (WebDriverException e) {
        // expected behavior
    }
    nameInput.sendKeys(user.getName());
    driver.findElement(By.id("input_preferedProgrammingLanguage")).click();
    driver.findElement(By.linkText(user.getProgrammingLanguage().getValue())).click();
    WebElement acceptAddsCheckbox = driver.findElement(By.id("input_adds"));
    Assert.assertEquals(acceptAddsCheckbox.isSelected(), false);
    acceptAddsCheckbox.click();
    takeScreenShot("User data entered.");
    Assert.assertEquals(driver.getCurrentUrl(), "and-activity://RegisterUserActivity");
    try {
        driver.getTitle();
        Assert.fail("Get title is not supported by SelendroidNativeDriver");
    } catch (WebDriverException e) {
        // expected behavior
    }

    driver.findElement(By.id("btnRegisterUser")).click();
}