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:botski.selenium.SocialBot.java

License:Apache License

/**
 * @throws Exception /*from  w ww .  j a  va  2 s.  co m*/
 */
public void pinterestLogin(String email, String password) throws Exception {
    browser.get("https://pinterest.com/login/?next=%2F");
    WebElement formEmail = browser.findElement(By.id("id_email"));
    formEmail.sendKeys(email);
    WebElement formPassword = browser.findElement(By.id("id_password"));
    formPassword.sendKeys(password);
    formPassword.submit();
    String url = browser.getCurrentUrl();
    if (url.contains("/login/")) {
        throw new Exception("Failed to login Pinterest as '" + email + "' using password '" + password
                + "', I ended up here '" + url + "'");
    }
}

From source file:br.eti.kinoshita.selenium.TestGoogle.java

License:Open Source License

@Test(groups = { "GoogleTest" }, /* dependsOnGroups={"LoginGroup"}, */dataProvider = "DataExcel")
public void testGoogle(String search, String result, ITestContext ctx, Method method) {
    this.addScreenShot(ctx, method, "Main page");

    WebElement inputQueryField = driver.findElement(By.name("q"));

    inputQueryField.sendKeys(search);//from   w ww. j  a v a 2 s .c om

    WebElement searchButton = driver.findElement(By.name("btnK"));

    searchButton.submit();

    // Wait for results to load
    Utils.waitForAssyncContent(driver, By.xpath("//h3[@class='r']//a"), getConfiguration()
            .getLong("selenium.timeout", 15000)); /* second parameter in getLong is a default value */

    List<WebElement> searchResults = driver.findElements(By.xpath("//h3[@class='r']//a")); // <h3 class='r'><a...

    this.addScreenShot(ctx, method, "Search results for " + search);

    Assert.assertNotNull(searchResults, "Couldn't find anything for query string " + search);

    boolean found = Boolean.FALSE;

    for (WebElement searchResult : searchResults) {
        if (searchResult.getText().toLowerCase().contains(result.toLowerCase())) {
            found = Boolean.TRUE;
            break;
        }
    }

    Assert.assertTrue(found,
            "Couldn't locate " + result + " in current page :" + getConfiguration().getString("selenium.url"));

}

From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java

License:Apache License

@Override
public void submit() {
    (new StaleExceptionResolver<Object>() {

        @Override//from w  ww  .j a va 2  s.  com
        public Object execute(WebElement element) {
            element.submit();
            return null;
        }
    }).waitForElement();

}

From source file:ch.vorburger.webdriver.reporting.tests.SampleGoogleSearchReportTest.java

License:Apache License

@Test
public void testGoogleSearch() {
    EventFiringWebDriver driverWithReporting;
    {/*from   w w  w. j  a  va2 s  . c o m*/
        // System.setProperty("webdriver.chrome.driver", "/opt/google/chrome/chrome");
        // WebDriver driver = new ChromeDriver();
        WebDriver driver = new FirefoxDriver();

        WebDriverEventListener loggingListener = new LoggingWebDriverEventListener(LOG_FILE_WRITER);
        ;
        driverWithReporting = new EventFiringWebDriver(driver);
        driverWithReporting.register(loggingListener);
    }

    driverWithReporting.get("http://www.google.com");
    WebElement element = driverWithReporting.findElement(By.name("q"));
    element.sendKeys("Mifos");
    element.submit();

    (new WebDriverWait(driverWithReporting, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("bfoot")));

    driverWithReporting.quit();
}

From source file:com.coinbot.core.Worker.java

License:Open Source License

@Override
public void run() {
    File pathToBinary = new File("/home/jian/Descargas/firefox46/bin/firefox");
    // Firefox 46 needed
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile profile = new FirefoxProfile();
    FirefoxDriver driver = new FirefoxDriver(ffBinary, profile);
    CoinbotApplication.ui.workerQueue.addWorker(workerPanel);

    while (CoinbotApplication.bot.isRunning()) {
        // Sacamos un "claim" de la cola
        Claim claim = CoinbotApplication.bot.getClaimQueue().next();
        if (claim == null) {
            continue;
        }/*from   www .  ja va2  s .c  o  m*/

        claim.getPanel().reset();
        claim.getPanel().getProgressBar().setMaximum(10);
        workerPanel.addClaim(claim.getPanel());
        claim.getPanel().nextStep("Opening URL");

        try {
            driver.manage().timeouts().pageLoadTimeout(12, TimeUnit.SECONDS);
            driver.navigate().to(new URL(claim.getFaucet().getUrl()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
            continue;
        } catch (TimeoutException e) {
            // Busca un elemento, si no lo encuentra que vuelva a cargar
            e.printStackTrace();
        }

        // Detectando captcha
        claim.getPanel().nextStep("Detecting Captcha");
        CaptchaDetector captchaDetector = new CaptchaDetector();
        CaptchaService captcha = null;

        try {
            captcha = captchaDetector.find(driver, driver.findElement(By.tagName("body")));
        } catch (NoSuchElementException ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Body not found!");
            continue;
        } catch (UnrecognizedCaptcha ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Captcha not recognized.");
            continue;
        } catch (Exception ex) {
            continue;
        }

        claim.getPanel().nextStep("Trying auto resolving");
        // Intentamos buscar el hash en la DB 
        CaptchaHash ch = new CaptchaHash(captcha);
        String answer = CoinbotApplication.captchaDatabase.getAnswer(ch.getHash());

        // Si no enctramos la respuesta en la bd se la pedimos al usuario
        if (answer == null) {
            claim.getPanel().nextStep("Waiting for captcha answer ...");

            // Encolar captcha
            CoinbotApplication.bot.getCaptchaQueue().toQueue(captcha);

            // Esperar la resolucion del captcha
            CaptchaTimer timer = new CaptchaTimer(captcha, 35);
            timer.start();

            // Esperamos a la resolucion
            while (!timer.isExpired() && !captcha.resolved()) {
                CoinbotApplication.ui.captchaQueue.getCaptchaPanel(captcha).setTimer(timer.getSecondsLeft());
            }

            if (!captcha.resolved()) {
                CoinbotApplication.captchaDatabase.addCaptcha(ch);
                continue;
            }
        }

        // Guardamos el captcha en la DB
        CoinbotApplication.captchaDatabase.addCaptcha(new CaptchaHash(captcha));

        // Y la imagen en un archivo
        try {
            ImageIO.write(captcha.getImage(), "png", new File("coinbot/captchas/" + ch.getHash() + ".png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Envia la respuesta al input
        captcha.answerToInput(driver);

        // Desencolar captcha
        CoinbotApplication.bot.getCaptchaQueue().deQueue(captcha);

        // Escribir address
        claim.getPanel().nextStep("Detecting input address");
        InputAddressDetector iad = new InputAddressDetector(driver);
        iad.insertAddress(claim.getBtcAddress());

        //claim.getPanel().nextStep("Detecting Antibot");
        // Detectar antibot (puzzle no soportado)
        // Resolver antibot

        // submit
        claim.getPanel().nextStep("Submiting ...");
        WebElement submit = driver.findElement(By.id("address"));
        submit.submit();

        claim.getPanel().nextStep("Checking response");
        //claim.getPanel().nextStep("Successfull claim!");
        /*WebElement out = null;
                
        try {
           out = driver.findElement(By.className("alert-success"));
        } catch (NoSuchElementException e) {
                   
        }
                
        try {
           out = driver.findElement(By.className("alert-danger"));
        } catch (NoSuchElementException e) {
        }
        */
        //claim.getPanel().nextStep("Failed claim!");

        claim.getPanel().done();
        workerPanel.removeClaim(claim.getPanel());
        claim.getTimer().done(2000, 1);
        CoinbotApplication.bot.getClaimQueue().toQueue(claim);

        try {
            Thread.sleep(25000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        driver.close();
    } catch (Exception e) {

    }
    CoinbotApplication.ui.workerQueue.removeWorker(workerPanel);
    System.out.println("Worker " + workerId + " end work!");
}

From source file:com.continuuity.test.TestUtil.java

License:Apache License

public void genericDeleteTest(String expectedUrl) {
    WebElement deleteForm = globalDriver.findElement(By.cssSelector(".delete-form"));
    deleteForm.submit();
    Global.driverWait(1);/*from w  ww.java2s. co m*/
    globalDriver.findElement(By.cssSelector(".action-submit-delete")).click();
    Global.driverWait(1);
    assertEquals(expectedUrl, globalDriver.getCurrentUrl());
}

From source file:com.ecfeed.core.runner.java.SeleniumTestMethodInvoker.java

License:Open Source License

private boolean performAction(WebElement webElement, String argument, MethodParameterNode methodParameterNode) {

    String action = methodParameterNode.getPropertyValue(NodePropertyDefs.PropertyId.PROPERTY_ACTION);

    if (action == null) {
        reportException("Action is undefined.", methodParameterNode);
    }/*from w w w .j  a v a  2 s. co m*/

    if (NodePropertyDefs.isActionSendKeys(action)) {
        webElement.sendKeys(argument);
        return true;
    }

    if (NodePropertyDefs.isActionClick(action)) {
        webElement.click();
        return true;
    }

    if (NodePropertyDefs.isActionSubmit(action)) {
        webElement.submit();
        return true;
    }

    return false;
}

From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java

License:Apache License

private void login(String email) {
    WebElement input = driver.findElement(By.cssSelector("input[type=text]"));
    input.clear();//from  ww  w. j  av a  2  s .co  m
    input.sendKeys(email);
    input.submit();
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 *
 * @param email {@link String}//w  w w .j a  v a 2 s . c o m
 */
@Override
public String login(final String email) {

    String loginURL = getDefaultHostAndPort() + "/login";
    getDriver().get(loginURL);

    if (driver.getCurrentUrl().endsWith("/login")) {

        WebElement element = findElementBy(By.name("username"));
        element.sendKeys(email);

        element = findElementBy(By.name("password"));
        element.sendKeys(getDefaultPass());

        element.submit();
    }

    return null;
}

From source file:com.gkopevski.fuelcheck.FuelCheckForm.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    try {//  w w w.  j av  a2 s  .co  m
        // Create a new instance of the html unit driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        driver = new PhantomJSDriver();
        ;

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

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

    } catch (Exception e) {
        e.printStackTrace();
    }
}