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:io.selendroid.tests.UserRegistrationTest.java

License:Apache License

private void registerUser(UserDO user) throws Exception {
    WebElement button = driver().findElement(By.id("startUserRegistration"));

    button.click();// w  ww  . j  av a  2s.  c  om

    WebElement username = driver().findElement(By.id("inputUsername"));

    username.sendKeys(user.getUsername());
    WebElement nameInput = driver().findElement(By.id("inputName"));
    Assert.assertEquals(nameInput.getText(), "Mr. Burns");
    nameInput.clear();
    nameInput.sendKeys(user.getName());

    driver().findElement(By.id("inputEmail")).sendKeys(user.getEmail());
    driver().findElement(By.id("inputPassword")).sendKeys(user.getPassword());
    try {
        nameInput.submit();
        Assert.fail("submit is not supported by SelendroidNativeDriver");
    } catch (WebDriverException e) {
        // expected behavior
    }

    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();

    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();
}

From source file:io.selendroid.webviewdrivertests.WebElementInteractionTest.java

License:Apache License

@Test()
public void shouldSubmitAnElement() {
    openWebdriverTestPage(HtmlTestData.SAY_HELLO_DEMO);

    WebElement inputField = driver().findElement(By.id("name_input"));
    Assert.assertNotNull(inputField);//from w  ww . ja  v a  2 s.c  o  m
    inputField.clear();
    inputField.sendKeys("Selendroid");

    inputField.submit();
    String name = (String) executeJavaScript("return document.title");
    Assert.assertEquals(name, "Hello: Selendroid");
}

From source file:io.tourniquet.pageobjects.DynamicElementGroupInterceptor.java

License:Apache License

@Override
public Object intercept(final Object o, final Method method, final Object[] objects,
        final MethodProxy methodProxy) throws Throwable {

    if (Modifier.isAbstract(method.getModifiers())) {
        if (elements.containsKey(method)) {
            WebElement element = elements.get(method).get();
            if ("form".equals(element.getTagName())) {
                element.submit();
            } else if (objects.length == 1) {
                element.clear();//w  ww . j  av  a  2 s  . c  o m
                element.sendKeys(objects[0].toString());
            } else if (objects.length == 0) {
                element.click();
            } else {
                throw new IllegalArgumentException("Method does not match web element " + element);
            }
            if (method.getReturnType().isAssignableFrom(o.getClass())) {
                return o;
            } else if (method.getReturnType().isAssignableFrom(WebElement.class)) {
                return element;
            }
            return null;

        } else {
            throw new NoSuchMethodException("Method " + method + " does not provide locator information");
        }

    }
    return methodProxy.invokeSuper(o, objects);
}

From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java

License:Apache License

/**
 * Called to login to the portal if necessary. 
 *//*from www  .j av a  2  s  .com*/
protected static void login() {

    driver.get(loginUrl);

    List<WebElement> uels = driver.findElements(By.id(usernameId));
    List<WebElement> pwels = driver.findElements(By.id(passwordId));

    // If there is no login or password fields, don't need to login.
    if (!uels.isEmpty() && !pwels.isEmpty()) {

        System.out.println("   No userid / password fields");
        WebElement userEl = uels.get(0);
        WebElement pwEl = pwels.get(0);

        // perform login
        userEl.clear();
        userEl.sendKeys(username);
        pwEl.clear();
        pwEl.sendKeys(password);
        pwEl.submit();

    }
}

From source file:jhc.redsniff.webdriver.SeleniumController.java

License:Apache License

@Override
public void submit(WebElement element) {
    element.submit();
}

From source file:juzu.impl.bridge.request.AbstractRequestFormParamDefaultEncoding.java

License:Apache License

@Test
public void testPathParam() throws Exception {
    driver.get(applicationURL().toString());
    WebElement paramElt = driver.findElement(By.id("param"));
    WebElement formElt = driver.findElement(By.id("trigger"));
    paramElt.sendKeys(AbstractTestCase.EURO);
    formElt.submit();
    checkEuro(param.getValue());//from  ww w .  ja  v  a  2s.  com
}

From source file:juzu.plugin.upload.AbstractUploadTestCase.java

License:Apache License

@Test
public void testUpload() throws Exception {
    driver.get(getURL().toString());//from   w ww.  j av a2 s . c om
    WebElement submit = driver.findElement(By.id("submit"));
    WebElement file = driver.findElement(By.id("file"));
    WebElement text = driver.findElement(By.id("text"));
    WebElement field = driver.findElement(By.id("field"));
    File f = File.createTempFile("juzu", ".txt");
    f.deleteOnExit();
    FileWriter writer = new FileWriter(f);
    writer.write("HELLO");
    writer.close();
    file.sendKeys(f.getAbsolutePath());
    text.sendKeys("text_value");
    field.sendKeys("field_value");
    AbstractUploadTestCase.contentType = null;
    AbstractUploadTestCase.content = null;
    AbstractUploadTestCase.text = null;
    submit.submit();
    assertTrue(AbstractUploadTestCase.contentType.startsWith("text/plain"));
    assertEquals("HELLO", AbstractUploadTestCase.content);
    assertEquals("text_value", AbstractUploadTestCase.text);
    assertEquals("field_value", AbstractUploadTestCase.field);
}

From source file:net.javacrumb.webview.webdriver.SimpleTest.java

License:Apache License

public static void main(String[] args) throws InterruptedException {
    // Create a new instance of the html unit driver
    // Notice that the remainder of the code relies on the interface,
    // not the implementation.
    //       WebDriver driver = new FirefoxDriver();
    WebDriver driver = new WebViewDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();
    ///*from w  w w .j a va2 s .c o  m*/
    //        // Check the title of the page
    //        System.out.println("Page title is: " + driver.getTitle());
    //
    //        driver.quit();

}

From source file:net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl.java

License:Open Source License

public void submit() {
    WebElement e = getWebElementByXPath("//input[@type='submit' or @type='image']", true, true);
    if (e == null) {
        e = getWebElementByXPath("//button[@type='submit']", true, true);
    }//  w  ww  . j av a  2s  .co m
    e.submit();
    throwFailingHttpStatusCodeExceptionIfNecessary(getServerResponseCode(), driver.getCurrentUrl());
}

From source file:net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl.java

License:Open Source License

public void submit(String nameOrID) {
    WebElement e = getWebElementByXPath("//input[(@type='submit' or @type='image') and (@name="
            + escapeQuotes(nameOrID) + " or @id=" + escapeQuotes(nameOrID) + ")]", true, true);
    if (e == null) {
        e = getWebElementByXPath("//button[@type='submit' and (@name=" + escapeQuotes(nameOrID) + " or @id="
                + escapeQuotes(nameOrID) + ")]", true, true);
    }/*w  w  w .  ja v a2 s .  co m*/
    e.submit();
    throwFailingHttpStatusCodeExceptionIfNecessary(getServerResponseCode(), driver.getCurrentUrl());
}