Example usage for org.openqa.selenium WebElement findElements

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

Introduction

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

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current context using the given mechanism.

Usage

From source file:co.uniandes.csw.ClinicaDeProblemas.test.UtiTest.java

@Test
public void testDeleteUTI() throws Exception {
    /**//  w  w w  . ja  v  a2 s  . c  om
     * Se hace clic en el vinculo "Delete" del primer elemento de la lista
     * de sports
     */
    driver.get(baseUrl + "/ClinicaDeProblemas.web/uTI.html");
    driver.findElement(By.linkText("Eliminar")).click();
    Thread.sleep(2000);
    /**
     * Se verifica que en la lista el elemento halla desaparecido. Si
     * existe, hubo un error.
     */
    try {
        List<WebElement> table = driver
                .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
        boolean fail = true;
        for (WebElement webElement : table) {
            List<WebElement> elems = webElement.findElements(By.xpath("td"));

        }

        WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
        // assertTrue(dialog != null && !fail);
    } catch (Exception e) {
        assertTrue(true);
    }

}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed

    try {/*  ww  w .  j a  v a  2 s  . c  o  m*/
        //            MarionetteDriverManager.getInstance().setup();
        System.out.println("Mulai Pencarian...");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;
        String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue();

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {

            //                    driver = new MarionetteDriver();
            driver = new ChromeDriver();
        }
        //       hmin = Integer.valueOf(args[0]).intValue();
        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;
        boolean keeploop = true;
        while (/**list==null || list.size() == 0**/
        keeploop) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggal.getSelectedIndex());

                ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(stFrom.getValue());

                ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(stTo.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();
                //          Thread.sleep(1000);
                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                if (list != null && list.size() > 0) {
                    List<WebElement> listForm = driver.findElements(By.tagName("form"));
                    for (WebElement form : listForm) {
                        List<WebElement> listInput = form.findElements(By.tagName("input"));
                        for (WebElement input : listInput) {
                            if (input.getAttribute("value").equalsIgnoreCase(kereta)) {
                                WebElement btn = form.findElement(By.className("itButton"));
                                btn.click();
                                System.out.println("========================>KLIK BOOKING");
                                keeploop = false;
                                throw new KlikException("BerhasilKlik");
                            }
                        }
                    }
                }
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (KlikException ke) {
                System.out.println("================> Masuk Klik Exception");
                keeploop = false;
                break;
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }

        //       System.out.println("ada keretaaaaaa: "+list.size());
        List<WebElement> listInput = driver.findElements(By.tagName("input"));
        for (WebElement input : listInput) {
            if (input.getAttribute("type").equals("checkbox")) {
                input.click();
                break;
            }
        }
        WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']"));
        lanjut.click();

        //Ngisi Tikete 
        //Nunggu disit
        //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul
        WebElement elementForWait = (new WebDriverWait(driver, 3))
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1")));
        //end wait
        WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1"));
        WebElement ktp = driver.findElement(By.id("txt_passport_1"));

        WebElement contactName = driver.findElement(By.id("txt_contact_first_name"));
        WebElement contactEmail = driver.findElement(By.id("txt_contact_email"));
        WebElement contactPhone = driver.findElement(By.id("txt_contact_phone"));
        WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address"));

        namaPenumpang.sendKeys(txtNamaPenumpang.getText());
        ktp.sendKeys(txtNoKTP.getText());
        contactName.sendKeys(txtNamaPenumpang.getText());
        contactEmail.sendKeys(txtEmail.getText());
        contactPhone.sendKeys(txtNoTelp.getText());
        contactAddress.sendKeys(txtAlamat.getText());

        playSound();

        JOptionPane.showMessageDialog(rootPane,
                "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi",
                JOptionPane.INFORMATION_MESSAGE);
        this.setAlwaysOnTop(true);

        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.atomicleopard.webelemental.Element.java

License:Open Source License

public Element parent() {
    EList<WebElement> list = new EListImpl<WebElement>();
    for (WebElement element : elements) {
        list.addAll(element.findElements(By.xpath("..")));
    }/*from  w  w w. j  a  v  a 2 s.co  m*/
    return new Element(list);
}

From source file:com.atomicleopard.webelemental.Element.java

License:Open Source License

public Element find(By selector) {
    EList<WebElement> list = new EListImpl<WebElement>();
    for (WebElement webElement : elements) {
        list.addAll(webElement.findElements(selector));
    }//from  w ww  .j  a  v  a  2 s. co m
    return new Element(list);
}

From source file:com.blogspot.jadecalyx.webtools.jcWebPage.java

public List<WebElement> GetWebList(String objectHandle) {
    Stack<jcPageObjectSet> lookupInfo = _pageObjectHelper.GetLookupDetails(objectHandle);
    WebElement el = extractElement(null, lookupInfo);
    List<WebElement> returnList = new ArrayList<WebElement>();
    List<WebElement> elements = el.findElements(By.cssSelector("li"));
    for (WebElement e : elements) {
        returnList.add(e);//  w w w . j  a va  2 s.  c  om
    }
    return returnList;
}

From source file:com.blogspot.jadecalyx.webtools.jcWebPage.java

private WebElement extractElement(WebElement currElement, Stack<jcPageObjectSet> cssStack) {
    if (cssStack.empty()) {
        return currElement;
    }/* w  w w .  j ava 2 s  . co m*/
    jcPageObjectSet currSet = cssStack.pop();
    List<WebElement> wel;
    if (currElement == null) {
        wel = _driver.findElements(By.cssSelector(currSet.GetDetails()));
    } else {
        wel = currElement.findElements(By.cssSelector(currSet.GetDetails()));
    }
    if (!wel.isEmpty()) {
        return extractElement(wel.get(0), cssStack);
    } else {
        return null;
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * FLAGGED FOR DELETION/*from w ww  .j  a v  a2  s  . c  o  m*/
 */
@Override
public String getTable(String locator) {
    log.debug("Getting table ...");
    String[] tableLocation = locator.split("\\.", 3);
    if (tableLocation.length != 3) {
        throw new RuntimeException("Incorrect table locator used");
    }
    WebElement table = findElement(tableLocation[0]);
    List<WebElement> allRows = table.findElements(By.tagName("tr"));
    List<WebElement> cells = allRows.get(Integer.parseInt(tableLocation[1])).findElements(By.tagName("td"));
    return cells.get(Integer.parseInt(tableLocation[2])).getText();
}

From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java

License:Open Source License

protected List<WebElement> waitForElementsAdded(WebElement inElement, String cssSelector) {
    List<WebElement> elements = Collections.EMPTY_LIST;

    long start = System.currentTimeMillis();
    while (elements.isEmpty() && System.currentTimeMillis() < (start + 20000)) {
        elements = inElement.findElements(By.cssSelector(cssSelector));
    }/*from   www  .  j  a  va2 s . c o  m*/

    if (elements.isEmpty()) {
        Assert.fail("Timed out waiting on elements matching CSS selector '" + cssSelector
                + "' to appear on the page.");
    }

    return elements;
}

From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java

License:Open Source License

protected void waitForElementsRemoved(WebElement inElement, String cssSelector) {
    List<WebElement> elements = inElement.findElements(By.cssSelector(cssSelector));

    long start = System.currentTimeMillis();
    while (!elements.isEmpty() && System.currentTimeMillis() < (start + 20000)) {
        elements = inElement.findElements(By.cssSelector(cssSelector));
    }//  ww  w .  j a v a2 s  .c  om

    if (!elements.isEmpty()) {
        Assert.fail("Timed out waiting on elements matching CSS selector '" + cssSelector
                + "' to be removed from the page.");
    }
}

From source file:com.cloudbees.workflow.ui.view.FailedJobTest.java

License:Open Source License

@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver")
@Test//from  w w  w. jav a 2 s.  c  o  m
public void test() throws Exception {
    WebDriver webdriver = getWebDriver();

    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");

    job.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build'); " + "   sh ('blah'); " + "}"));

    QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0);
    jenkinsRule.assertBuildStatus(Result.FAILURE, build.get());

    String jobUrl = getItemUrl(jenkinsRule.jenkins, job);
    webdriver.get(jobUrl);

    // Make sure the stage cell was marked as failed...
    List<WebElement> failedStageCells = webdriver
            .findElements(By.cssSelector(".stage-cell.FAILED .stage-wrapper"));
    Assert.assertEquals(1, failedStageCells.size());

    // Make the sure the stage-failed-popover widget was added to the cell
    WebElement failedStageCell = failedStageCells.get(0);
    List<WebElement> stageFailedPopovers = failedStageCell
            .findElements(By.cssSelector(".stage-failed-popover"));
    Assert.assertEquals(1, stageFailedPopovers.size());

    // Make sure that when we mouse over the failed stage cell we get a popup...
    moveMouseToElement(webdriver, failedStageCell);
    List<WebElement> popovers = waitForElementsAdded(webdriver, ".cbwf-popover");
    //        System.out.println(webdriver.getPageSource());
    Assert.assertTrue(popovers.size() > 0);

    // Make sure the popover has what we expect...
    Assert.assertEquals("Failed with the following error(s)\n" + "Shell Script script returned exit code 127\n"
            + "See stage logs for more detail.\n" + "Logs", popovers.get(0).getText().trim());

    // Make sure the popover is removed once we move off it
    //moveMouseOffElement(webdriver);
    //waitForElementsRemoved(webdriver, ".cbwf-popover");
}