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:com.vmware.veei.qe.devcenter.SampleExchangeTest.java

/**
 * S87863: [Sample Exchange] Request New Samples , Check Edit Link and
 * Delete Link S87869: [Sample Exchange] Vote for Sample Requests
 *
 *///from w ww .  j av a2  s.  c  o  m
@Test(groups = { "test", "stage" })
@NavigateTo(SAMPLE_CODE_URL)
public void testAddNewRequest() {
    // #action 1: Selecting request tab
    selectTab("Requests");

    // Input parameters
    String requestTitle = "Test Request";
    String language = "java";
    String sdkTool = "Airwatch";

    // #action 2: Adding request with Input parameters
    addRequest(requestTitle, language, sdkTool);
    // #expects: Verifying the fields with Input parameters
    assertThat(driver.findElement(By.cssSelector(".metadata")).getText()).contains(language);
    assertThat(driver.findElement(By.cssSelector(".metadata")).getText()).contains(sdkTool);
    assertThat(driver.findElement(By.cssSelector(".readme")).getText()).contains("Test Description");
    assertThat(driver.findElement(By.cssSelector(".header-title h1")).getText()).isEqualTo(requestTitle);
    assertThat(driver.findElement(By.cssSelector(".tag")).getText()).isEqualTo("testing");

    // #action 3: Check Post New Comment Functionality
    WebElement commentSection = driver.findElement(By.cssSelector(".comments"));

    String currentCommentValue = commentSection.findElement(By.cssSelector(".badge")).getText();

    WebElement commentsTextArea = driver.findElement(By.name("request-comment"));
    commentsTextArea.sendKeys("Test Comment");

    driver.findElement(By.cssSelector(".comments input[type='submit']")).click();
    WebElement newCommentSection = driver.findElement(By.cssSelector(".comments #comments .badge"));
    // #expects: Verifying the comment section with commentvalue (should not be equal )
    assertThat(newCommentSection.getText()).isNotEqualTo(currentCommentValue);
    List<WebElement> tabsAvailable = driver.findElements(By.cssSelector("#tabs .nav-tabs li a"));
    assertThat(tabsAvailable.size()).isGreaterThan(0);
    // #action 4: Select Tab : Solution
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    jse.executeScript("$('a[href=#tab-solutions]').parent().click();");
    jse.executeScript("$('#tab-solutions').css('display','block');");

    new WebDriverWait(driver, 30)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".solution-radio-form")));

    // #action 5: Edit functionality test
    driver.findElement(By.cssSelector(".author-actions .edit a")).click();

    WebElement anchor = driver.findElement(By.cssSelector(".form-horizontal input[type='submit']"));
    anchor.submit();

    // #action 6: Deleting the request sample Entry

    jse.executeScript("$('.request-delete-dialog').submit();");

    new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#search-results-list")));
}

From source file:com.watchrabbit.crawler.auth.service.AuthServiceImpl.java

License:Apache License

@Override
public Collection<Cookie> getSession(String domain) {
    Collection<Cookie> cookies = sessionRepository.findByDomain(domain);
    if (cookies != null) {
        return cookies;
    }//  ww w  .  j av  a  2 s .c  o m
    RemoteWebDriver driver = remoteWebDriverFactory.produceDriver();
    try {
        AuthData authData = authDataDao.findByDomain(domain);
        if (authData == null) {
            LOGGER.info("Cannot find auth data for {}", domain);
            return emptyList();
        }
        driver.get(authData.getAuthEndpointUrl());
        loaderService.waitFor(driver);

        WebElement loginForm = locateLoginForm(driver);
        if (loginForm == null) {
            LOGGER.error("Cannot locate any form that matches criteria on {}", authData.getAuthEndpointUrl());
            return emptyList();
        }
        WebElement password = findPasswordInput(loginForm);
        LOGGER.debug("Found password field with name {}", password.getAttribute("name"));
        WebElement login = findLoginInput(loginForm);
        LOGGER.debug("Found login field with name {}", login.getAttribute("name"));

        login.sendKeys(authData.getLogin());
        password.sendKeys(authData.getPassword());
        loginForm.submit();
        loaderService.waitFor(driver);

        cookies = driver.manage().getCookies();
        Calendar now = clock.getCalendar();
        now.add(Calendar.SECOND, authData.getSessionDuration());
        sessionRepository.save(domain, cookies, now.getTime());
        return cookies;
    } finally {
        remoteWebDriverFactory.returnWebDriver(driver);
    }
}

From source file:com.zhao.crawler.util.CookieUtil.java

License:Open Source License

/**
 * csdn??cookies?/*from w  ww .j  a va2s .c  om*/
 * 
 * @param username
 *            ??
 * @param password
 *            ?
 * @param geckodriverpath
 *            gecko?https://github.com/mozilla/geckodriver
 * @param savecookiepath
 *            cookies?
 * @throws Exception
 */
public static void firfoxDriverGetCookies(String username, String password, String geckodriverpath,
        String savecookiepath) throws Exception {
    // ???
    System.setProperty("webdriver.gecko.driver", geckodriverpath);
    FirefoxDriver driver = new FirefoxDriver();
    String baseUrl = "http://kaixin65.com/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login";
    // url
    driver.get(baseUrl);
    // ?
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    // ??
    WebElement elemUsername = driver.findElement(By.name("username"));
    WebElement elemPassword = driver.findElement(By.name("password"));
    WebElement btn = driver.findElement(By.className("logging"));
    WebElement rememberMe = driver.findElement(By.id("rememberMe"));
    // ??
    elemUsername.sendKeys(username);
    elemPassword.sendKeys(password);
    rememberMe.click();
    // ???
    btn.submit();
    Thread.sleep(5000);
    driver.get("http://msg.csdn.net/");
    Thread.sleep(5000);
    // ?cookies
    driver.manage().getCookies();
    Set<org.openqa.selenium.Cookie> cookies = driver.manage().getCookies();
    System.out.println("Size: " + cookies.size());
    Iterator<org.openqa.selenium.Cookie> itr = cookies.iterator();

    CookieStore cookieStore = new BasicCookieStore();

    while (itr.hasNext()) {
        Cookie cookie = itr.next();
        BasicClientCookie bcco = new BasicClientCookie(cookie.getName(), cookie.getValue());
        bcco.setDomain(cookie.getDomain());
        bcco.setPath(cookie.getPath());
        cookieStore.addCookie(bcco);
    }
    // ?
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(savecookiepath)));
    oos.writeObject(cookieStore);
    oos.close();

}

From source file:core.PluginManagerTest.java

License:Open Source License

@Test
@WithPlugins("gerrit-trigger")
public void uninstall_plugin() throws InterruptedException, ExecutionException {
    assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart());
    jenkins.getPluginManager().visit("installed");
    check(find(by.url("plugin/gerrit-trigger")), false);
    WebElement form = find(by.action("plugin/gerrit-trigger/uninstall"));
    form.submit();
    jenkins.restart();/*from ww  w .j  av a2s  .co  m*/
    jenkins.getPluginManager().visit("installed");
    WebElement trigger = find(by.url("plugin/gerrit-trigger"));
    assertFalse(trigger.isSelected());
}

From source file:corpus.sinhala.crawler.blog.rss.RssSearcher.java

License:Apache License

@Override
public void run() {
    RssWebDriver driver = RssWebDriver.getInstance();
    try {// w  w w. j  av a 2s  .com
        while (true) {

            if (!driver.acquired()) {
                if (driver.acquire()) {
                    break;
                }
            }
            Thread.sleep(10);

        }
        driver.get(ConfigManager.getProperty(ConfigManager.FEED_BURNER_URL)); //test here
        WebElement element = driver.findElement(By.name("sourceUrl"));
        element.sendKeys(url);
        element.submit();

        List<WebElement> elements = driver.findElements(By.className("checkboxLabel")); //test here
        for (int i = 0; i < elements.size(); i++) {

            try {
                if (elements.get(i).getText().contains("RSS")) {
                    String[] s = elements.get(i).getText().split(" ");
                    //System.out.println(s[s.length - 1]);
                    RSSFeedParser parser = new RSSFeedParser(s[s.length - 1]);
                    String blogId = parser.getBlogId();
                    //System.out.println(blogId);
                    Feed feed = parser.getFeed(blogId); //test here
                    for (FeedMessage message : feed.getMessages()) {

                        boolean contains = false;
                        String postId = message.getId();
                        if (CacheManager.getInstance().postCache.containsKey(blogId)) {
                            if (CacheManager.getInstance().postCache.get(blogId).contains(postId)) {
                                contains = true;
                                //System.out.println("Contain post id " +postId);
                            } else {
                                CacheManager.getInstance().postCache.get(blogId).add(postId);
                                CacheManager.getInstance().serializeCache();
                                //System.out.println("Not Contain post id " +postId);
                            }
                        } else {
                            Set<String> postIds = new HashSet<>();
                            postIds.add(postId.trim());
                            CacheManager.getInstance().postCache.put(blogId, postIds);
                            CacheManager.getInstance().serializeCache();

                        }
                        if (!contains) {
                            BufferedWriter writer = null;

                            Post post = new Post();
                            post.setLink(this.url);
                            post.setTopic(message.getTitle());
                            post.setCategory("BLOG");
                            post.setAuthor(message.getAuthor());
                            post.setContent(getAcceptedSentences(message.getDescription()));

                            String date = message.getDate();
                            date = date.split("T")[0];
                            String parts[] = date.split("-");
                            post.setYear((parts[0]));
                            post.setMonth((parts[1]));
                            post.setDay((parts[2]));

                            XMLFileWriter.getInstance().addPost(post);

                        }

                    }
                }
            } catch (Exception e) {
                logger.error(e);
            }
        }
        Thread.sleep(1000);

    } catch (Exception ex) {

        logger.error(ex);
    }

    driver.release();
    driver.decrease();
}

From source file:corpus.sinhala.crawler.blog.rss.RssWebDriver.java

License:Apache License

public static RssWebDriver getInstance() {
    if (instance != null) {
        return instance;
    } else {/*from  w w  w  . j a v a 2  s .c  o  m*/
        instance = new RssWebDriver();

        instance.get(ConfigManager.getProperty(ConfigManager.FEED_BURNER_URL));
        WebElement element = instance.findElement(By.name("Email"));
        element.sendKeys(ConfigManager.getProperty(ConfigManager.GOOGLE_ID));
        element = instance.findElement(By.name("Passwd"));
        element.sendKeys(ConfigManager.getProperty(ConfigManager.GOOGLE_PASSWORD));
        element.submit();
        return instance;
    }
}

From source file:de.dentrassi.pm.testing.ChannelTester.java

License:Open Source License

public static ChannelTester create(final WebContext context, final String name) {
    // get before list of channels

    final Set<String> before = getAllChannelIds(context);

    // create channel

    context.getDriver().get(context.resolve("/channel/createWithRecipe"));
    final WebElement element = context.findElement(By.id("name"));
    element.sendKeys(name);/*  w ww.j a  va 2  s . c o  m*/
    element.submit();

    // get after list of channels

    final Set<String> after = getAllChannelIds(context);
    after.removeAll(before);

    if (after.isEmpty()) {
        throw new RuntimeException(String.format("Channel '%s' did not get created", name));
    }

    if (after.size() > 1) {
        throw new RuntimeException(
                String.format("More than one channel was created when adding channel '%s'", name));
    }

    // return new channel

    return new ChannelTester(context, after.iterator().next());
}

From source file:de.dentrassi.pm.testing.ChannelTester.java

License:Open Source License

/**
 * Upload a file to the channel//w ww  .  j a v a2s  .c om
 *
 * @param localFileName
 *            the file to upload
 * @return a set of artifact ids which got created by this operation. This
 *         list may be empty or contain one or more artifacts
 */
public Set<String> upload(final String localFileName) {
    final Set<String> before = getAllArtifactIds();

    get(String.format("/channel/%s/add", this.id));

    final WebElement link = this.context.findElement(By.linkText("Upload"));

    Assert.assertTrue(link.findElement(By.xpath("..")).getAttribute("class").contains("active"));
    ;

    // upload file

    final File input = this.context.getTestFile(localFileName);

    {
        final WebElement ele = this.context.findElement(By.id("file"));
        Assert.assertNotNull(ele);

        ele.sendKeys(input.toString());
        ele.submit();
    }

    final Set<String> after = getAllArtifactIds();

    after.removeAll(before);

    return after;
}

From source file:de.dentrassi.pm.testing.DebTest.java

License:Open Source License

@Test
public void testDeb2() throws Exception {
    final ChannelTester ct = ChannelTester.create(getWebContext(), "deb2");
    ct.addAspect("deb");
    ct.addAspect("apt");

    {/*  w ww.j a  v a2s .c  o  m*/
        final Set<String> result = ct.upload("data/deb/org.eclipse.scada_0.2.1_all.deb");
        Assert.assertEquals(1, result.size());
    }
    Assert.assertEquals(1, ct.getAllArtifactIds().size());

    testUrl(String.format("/apt/%s", ct.getId())); // index page

    getWebContext().getResolved(String.format("/config/deb/channel/%s/edit", ct.getId()));

    final WebElement desc = getWebContext().findElement(By.name("description"));
    desc.sendKeys("Test Description");
    desc.submit();

    testUrl(String.format("/apt/%s", ct.getId())); // index page

    testUrl(String.format("/apt/%s/dists/default/Release", ct.getId()));
    testUrl(String.format("/apt/%s/dists/default/main/binary-amd64/Release", ct.getId()));
    testUrl(String.format("/apt/%s/dists/default/main/binary-amd64/Packages", ct.getId()));
    testUrl(String.format("/apt/%s/dists/default/main/binary-i386/Release", ct.getId()));
    testUrl(String.format("/apt/%s/dists/default/main/binary-i386/Packages", ct.getId()));
}

From source file:de.dentrassi.pm.testing.DeployGroupTest.java

License:Open Source License

@Test
public void testCreateDeployGroup() throws Exception {
    final WebContext ctx = getWebContext();
    final WebDriver driver = ctx.getResolved("/deploy/auth/addGroup");

    final WebElement nameField = driver.findElement(By.id("name"));
    nameField.sendKeys("m1");
    nameField.submit();

    for (final WebElement ele : ctx.findElements(By.tagName("tr"))) {
        final List<WebElement> cells = ele.findElements(By.tagName("td"));
        if (cells.isEmpty()) {
            // header line
            continue;
        }//from w w w . j  ava2s.c  om

        final String name = cells.get(0).getText();
        if (name.equals("m1")) {
            addKey(cells.get(1).getText());
        }
    }
}