Example usage for org.openqa.selenium WebDriver findElement

List of usage examples for org.openqa.selenium WebDriver findElement

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElement.

Prototype

@Override
WebElement findElement(By by);

Source Link

Document

Find the first WebElement using the given method.

Usage

From source file:testTheClient.java

@Test
public void verifyAlterations() throws Exception {

    WebElement editButton = null;//  w ww .  j  a  va  2  s .  c  om
    List<WebElement> rows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    ;
    for (int i = 0; i < rows.size(); i++) {
        if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = rows.get(i);
            break;
        }
    }
    editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0);
    //click the edit button
    editButton.click();
    //clear description field and type coolscars 
    WebElement element = driver.findElement(By.id("description"));
    element.clear();
    element.sendKeys("cool cars");
    driver.findElement(By.xpath("//*[@id=\"save\"]")).click();
    List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    ;
    String newDescr = null;
    for (int i = 0; i < updatedRows.size(); i++) {
        if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            newDescr = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText();
            break;
        }
    }
    assertThat(newDescr, is("cool cars"));
}

From source file:testTheClient.java

@Test
public void testFieldErrorPrompt() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("save")).click();

    String errorMessage = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<String>) (WebDriver d) -> {
                return d.findElement(By.xpath("//*[@id=\"submiterr\"]")).getText();
            });/*from   ww w . j  av a 2  s. c  o m*/
    Assert.assertThat(errorMessage, is("All fields are required"));
}

From source file:testTheClient.java

@Test
public void zCreateNewCarEntry() throws Exception {
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<String>) (WebDriver d) -> {
        return d.findElement(By.xpath("//*[@id=\"new\"]")).getText();
    });//from   w  ww  .ja v a  2s.  c om
    //populate fields
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");
    //save
    driver.findElement(By.id("save")).click();
    List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    assertThat(updatedRows.size(), is(6));
    assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(1).getText(), is("2008"));
    assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(4).getText(), is("Rio"));

}

From source file:ClientServicesQA.java

public void loginToClientServices(String url, WebDriver driver) throws InterruptedException {
    String institutionName = "Client Services";
    String userName = "MHCampusAutomationAdmin";
    String password = "12345678";

    driver.manage().window().maximize();
    driver.get(url);/*from  www.  jav  a  2  s . co  m*/

    driver.findElement(By.id("TextBoxInstitution")).clear(); // clearing the institution text box
    driver.findElement(By.id("TextBoxInstitution")).sendKeys(institutionName); // enter institution name
    driver.findElement(By.id("TextBoxUsername")).clear(); // enter user name
    driver.findElement(By.id("TextBoxUsername")).sendKeys(userName);// clearing the user name text box
    driver.findElement(By.id("TextBoxPassword")).clear(); // enter password
    driver.findElement(By.id("TextBoxPassword")).sendKeys(password);// clearing the password text box

    driver.findElement(By.id("ButtonLogin")).click(); //Clicking on the Login button

    Thread.sleep(2000);
    //driver.findElement(By.partialLinkText("Convert")).click(); // find element by partial text
    //driver.findElement(By.id("ctl00_LoginStatus1")).click();

    driver.close();
}

From source file:ClientServicesQA.java

public void createNewTegrityCustomer(WebDriver driver) throws Exception {
    driver.findElement(By.linkText("Create Tegrity customer")).click();
    Thread.sleep(2000);//from w w  w.  j  a  v  a 2  s .  c  o m
    driver.close();
}

From source file:openCloseTables.java

public static void main(String[] args) throws IOException {

    System.setProperty("webdriver.ie.driver",
            "C:\\Users\\Colin Cook\\Desktop\\selenium-2.53.1\\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();

    driver.get("http://10.0.1.53/opstar_test/");

    out.println("Launching Internet Explorer browser..");
    driver.manage().window().maximize();

    try {//w w  w .  j a v a 2s  .c  o  m
        Thread.sleep(3000); // pauses for 3 seconds
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    out.println("The title of the page being tested is:   " + driver.getTitle());

    WebElement acknowledge = driver
            .findElement(By.xpath("html/body/div[5]/div[1]/div[2]/div[2]/div[1]/div/div[2]/center/a"));
    acknowledge.click(); //first popup when you go on site

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement applications = //driver.findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[5]/a/span"));
            driver.findElement(By.linkText("Applications"));
    applications.click();

    WebElement toTools = driver
            .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/a"));
    toTools.click();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement traingFolder = driver
            .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/ul/li/a"));
    traingFolder.click();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeBox = driver.findElement(By.id("cboxClose"));
    closeBox.click(); //clicks second popup acknolwedge box

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement textBox = driver.findElement(By
            .xpath("html/body/div[3]/div[4]/div[2]/div/div[1]/div/div[2]/div/form/div/div/span/span[1]/span"));
    textBox.click();

    textBox.sendKeys("ken"); //first three letters of someones name

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    textBox.sendKeys(Keys.ENTER);

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table1 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[1]/div/a[2]"));
    table1.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table1.click();

    out.println("The Designations folder has been successfully opened and closed");
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table2 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/div/a[2]"));
    table2.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table2.click();
    out.println("The Waivers folder has been successfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table3 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[1]/div/a[2]"));
    table3.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table3.click();
    out.println("The Professional Licenses/ Certificates / Medical folder has been opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table4 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[1]/div/a[2]"));
    table4.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table4.click();
    out.println("The First Aid folder has been succesfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table5 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[1]/div/a[2]"));
    table5.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table5.click();
    out.println("The Star folder has been successfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table6 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/div/a[2]"));
    table6.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    table6.click();
    out.println("The Training Courses and Tests folder has been successfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table7 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[1]/div/a[2]"));
    table7.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table7.click();
    out.println(
            "The Professional Development / Individual Development Plan folder has been successfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table8 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[1]/div/a[2]"));
    table8.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    table8.click();
    out.println("The FLETC Certificates folder has been successfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table9 = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[1]/div/a[2]"));
    table9.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    table9.click();
    out.println("The Miscellaneous folder has been succesfully opened and closed");

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement qualifications = driver
            .findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[1]/div/a[2]"));
    qualifications.click();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    qualifications.click();
    out.println("The Qualifications folder has been successfully opened and closed");

    // I should program test scripts like this in the future

    //        try {
    //            WebElement xbox = driver.findElement(By.id("cboxClose"));
    //            xbox.click();
    //        } catch(Exception e) {
    //            System.err.print("NO NO NO that ");
    //        }

}

From source file:FormFiller.java

private static void pseudoMain(String[] args) throws IOException {
    if (args.length < 3 || args.length > 5)
        throw new IllegalArgumentException("Usage: lastName bankName deliveryDate [firstName] [print]\n"
                + "e.g. Hakim Ally 01/01/2016 OR Hakim Chase 1/1/2016 William print\n");

    if (args[args.length - 1].equals("print")) {
        print = true;//  w ww . j  a v  a 2 s .  c  om
    }

    WebDriver driver = getNewFirefoxDriver();

    driver.get("https://www.dealertrack.com/default1.aspx?RefreshBy=SM");

    HashMap dealerTrackData = new HashMap();

    try {

        WebElement username = driver.findElement(By.name("username"));
        username.sendKeys("whakim");
        WebElement pwd = driver.findElement(By.name("password"));
        pwd.sendKeys("keepbeepin23");
        driver.findElement(By.name("login")).submit();

        JavascriptExecutor jse = (JavascriptExecutor) driver;

        jse.executeScript("var script = document.createElement('script');\n"
                + "script.src = \"https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js\";\n"
                + "document.getElementsByTagName('head')[0].appendChild(script);");

        jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                + "firstElementChild.contentDocument.getElementById('AppStatus').click()");

        int attempts = 0;
        while (attempts++ < 15) {
            Thread.sleep(500);
            try {
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('txtSearchValue').value = '" + args[0] + "'");
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('btnSearch').click();");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 15)
                    e.printStackTrace();
            }
        }

        jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                + "contentDocument.getElementById('btnSearch').click();");

        attempts = 0;
        String firstLenderName = null;
        int boxNum = -1;

        while (attempts++ < 10) {
            Thread.sleep(750);
            try {
                String boxName = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                + "body.childNodes[2].contentDocument.getElementById('applications_ctrl"
                                + ++boxNum + "_Tapplications_ctrl" + boxNum + "_TR').innerHTML");
                int comma = boxName.indexOf(',');

                if (comma == -1 || !(boxName.substring(0, comma).contains(args[0]))) {
                    boxNum--;
                    continue;
                }

                else if (args.length > 3 && !args[3].equals("print")
                        && !boxName.substring(comma, boxName.length()).contains(args[3]))
                    continue;

                long numApplications = (long) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                + "body.childNodes[2].contentDocument.getElementsByClassName('lender_decisions')["
                                + boxNum + "]." + "childNodes[0].childElementCount");
                String firstLenderResult = (String) jse.executeScript("return document.getElementById('iFrm')."
                        + "contentWindow.document.body.childNodes[2].contentDocument.getElementsByClassName"
                        + "('lender_decisions')[" + boxNum + "].childNodes[0].childNodes[0].className");

                firstLenderName = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow."
                                + "document.body.childNodes[2].contentDocument.getElementsByClassName('lender_decisions')["
                                + boxNum + "]." + "childNodes[0].childNodes[0].childNodes[0].innerHTML");

                if (!firstLenderName.equals(args[1]) && numApplications == 1)
                    continue;

                String secondLenderResult = null;

                if (numApplications > 1) {
                    secondLenderResult = (String) jse.executeScript("return document.getElementById('iFrm')."
                            + "contentWindow.document.body.childNodes[2].contentDocument.getElementsByClassName"
                            + "('lender_decisions')[" + boxNum + "].childNodes[0].childNodes[1].className");
                }

                if (firstLenderResult.contains("declined")
                        && ((numApplications > 1) ? secondLenderResult.contains("declined")
                                : secondLenderResult == null))
                    continue;

                break;

            } catch (WebDriverException e) {
                boxNum--;
                if (attempts >= 10)
                    e.printStackTrace();
            }
        }

        attempts = 0;
        String apr = null;

        if (args[1].equals("Chase")) {

            if (firstLenderName.equals("Chase"))
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[0].childNodes[0].click()");

            else
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[1].childNodes[0].click()");

            // APR
            while (attempts++ < 10) {
                Thread.sleep(1500);
                try {
                    apr = (String) jse
                            .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                    + "body.childNodes[2].contentDocument.getElementById('appDetails').contentDocument."
                                    + "getElementById('divHtml').childNodes[1].childNodes[1].childNodes[4].childNodes[1]."
                                    + "childNodes[5].firstElementChild.childNodes[0].childNodes[3].childNodes[3].childNodes[1]."
                                    + "childNodes[10].childNodes[3].childNodes[0].nodeValue");
                    break;
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                }
            }

            dealerTrackData.put("Text201", "JPMorgan Chase Bk");
            dealerTrackData.put("fullBankName", "JPMorgan Chase Bk\nPO Box 901098\nFort Worth, TX 76101-2098");

        }

        else if (args[1].equals("Ally")) {

            if (firstLenderName.equals("Ally"))
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[0].childNodes[0].click()");

            else
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[1].childNodes[0].click()");

            // APR
            while (attempts++ < 10) {
                Thread.sleep(1500);
                try {
                    apr = (String) jse
                            .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                    + "body.childNodes[2].contentDocument.getElementById('appDetails').contentDocument."
                                    + "getElementById('divHtml').childNodes[1].childNodes[1].childNodes[4].childNodes[1].childNodes[3]."
                                    + "childNodes[1].childNodes[2].childNodes[1].childNodes[2].childNodes[3].childNodes[1]."
                                    + "lastElementChild.childNodes[3].childNodes[0].data");
                    break;
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                }

            }

            // Lienholder Name
            String lienName = null;
            attempts = 0;

            for (int i = 6; lienName == null
                    || !(lienName.contains(";") && lienName.contains("Ally")); i += 2, attempts++) {
                try {
                    lienName = tryAllyBox(jse, i);
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                    Thread.sleep(50);
                }
            }

            dealerTrackData.put("Text201", lienName.substring(1, lienName.indexOf(";")));

            dealerTrackData.put("fullBankName", "Ally Bank\nP.O. Box 8128\nCockeysville, MD 21030");
        }

        else
            throw new IOException("Unsupported bank: " + args[1] + ". Choose Chase or Ally.");

        dealerTrackData.put("Text15", apr.substring(0, apr.length() - 2));

        Thread.sleep(1200);

        // Navigate to Application Info
        attempts = 0;
        while (attempts++ < 10) {
            Thread.sleep(50);
            try {
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementById('appDetails').contentDocument.getElementById('divBtn').childNodes[4].childNodes[1].click()");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 10)
                    e.printStackTrace();
            }
        }

        attempts = 0;
        while (attempts++ < 15) {
            Thread.sleep(500);
            try {
                try {
                    jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                            + "childNodes[2].contentDocument.getElementById('optAction_0').checked = true");
                    break;
                } catch (WebDriverException e) {
                    jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                            + "childNodes[2].contentDocument.getElementById('optAction_copy_0').checked = true");
                    break;
                }
            } catch (WebDriverException e) {
                if (attempts >= 15) {
                    e.printStackTrace();
                }
            }
        }

        attempts = 0;
        while (attempts++ < 10) {
            Thread.sleep(250);
            try {
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('btncontinue').click()");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 10) {
                    e.printStackTrace();
                }
            }
        }

        // Sale ID
        attempts = 0;
        String sid = null;

        while (attempts++ < 20) {
            Thread.sleep(750);
            try {
                sid = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                                + "childNodes[2].contentDocument.getElementById('app_stock_num').value");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 20) {
                    e.printStackTrace();
                }
            }
        }

        dealerTrackData.put("Text3", sid);

        // Figure out what state the buyer is in
        dealerTrackData.put("buyerState", (String) jse.executeScript("return document.getElementById('iFrm')."
                + "contentWindow.document.body.childNodes[2].contentDocument.getElementById('app_state').value"));

        // Buyer Name and Address
        String firstName = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_first_name').value");

        String lastName = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_last_name').value");

        // Store applicant's name for PDF naming
        String fullName = firstName + " " + lastName;
        dealerTrackData.put("fullName", fullName);

        String address0 = (String) jse.executeScript("return ((document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_street_num').value).concat(' '))."
                + "concat(document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                + "getElementById('app_street_name').value)");

        String aptNum = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_apt_num').value");

        if (!aptNum.equals(""))
            address0 = address0 + " " + aptNum;

        String city = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_city').value");

        String state = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_state').value");

        String zipCode = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_zip_code').value");

        dealerTrackData.put("Text5", fullName + "\n" + address0 + "\n" + city + ", " + state + " " + zipCode);

        // Fill Name/Address Lines in Ally Credit App + Confirmation of Insurance, if applicable

        if (args[1].equals("Ally") || dealerTrackData.get("buyerState").equals("TX")) {
            dealerTrackData.put("Last Name (or trade name of business)", lastName);
            dealerTrackData.put("First", firstName);
            dealerTrackData.put("Present Address", address0);
            dealerTrackData.put("Zip Code", zipCode);
            dealerTrackData.put("City", city);
            dealerTrackData.put("State", state);
        }

        dealerTrackData.put("addressLine", address0 + ", " + city + ", " + state + " " + zipCode);

        boolean cosigner = false;

        // Co-Signer Name and Address (if applicable)
        try {
            String coAppFirstName = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_first_name').value");

            String coAppLastName = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_last_name').value");

            String coAppFullName = coAppFirstName + ' ' + coAppLastName;

            // Store Co-App Full Name (for TX Contract)
            dealerTrackData.put("coAppFullName", coAppFullName);

            String coAppAddress0 = (String) jse
                    .executeScript("return ((document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_street_num').value).concat(' '))."
                            + "concat(document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                            + "getElementById('app_co_street_name').value)");

            String coAppAptNum = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_apt_num').value");

            if (!coAppAptNum.equals(""))
                coAppAddress0 = coAppAddress0 + " " + coAppAptNum;

            String coAppCity = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_city').value");

            String coAppState = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_state').value");

            String coAppZipCode = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_zip_code').value");

            dealerTrackData.put("Text6", coAppFullName + "\n" + coAppAddress0 + "\n" + coAppCity + ", "
                    + coAppState + " " + coAppZipCode);

            if (args[1].equals("Ally") || dealerTrackData.get("buyerState").equals("TX")) {
                dealerTrackData.put("First2", coAppFirstName);
                dealerTrackData.put("Last Name (or trade nameof business)2", coAppLastName);
                dealerTrackData.put("Present Address2", coAppAddress0);
                dealerTrackData.put("Zip Code2", coAppZipCode);
                dealerTrackData.put("City2", coAppCity);
                dealerTrackData.put("State2", coAppState);
            }

            cosigner = true;

        } catch (WebDriverException e) {
            dealerTrackData.put("cosignerNullField", "N/A");
        }

        // Car Year
        String carYear = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementById('app_auto_yearList').value");
        dealerTrackData.put("Text9", carYear);

        // Car Make and Model
        String carMake = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_makeList').value");

        String carModel = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_modelList').value");

        dealerTrackData.put("Text10", carMake + ' ' + carModel);

        dealerTrackData.put("Make", carMake);
        dealerTrackData.put("Model", carModel);

        // Style/Trim
        String carStyleTrim = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_trimList').value");
        dealerTrackData.put("StylefTrim", carStyleTrim);

        // VIN
        String vin = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementById('app_vin_num').value");
        dealerTrackData.put("Text12", vin);

        // Amount Financed
        if (args[1].equals("Chase"))
            recalculateChaseStructure(jse);

        String amountFinanced = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_est_amt_financed')[0].value");
        double amountFinancedDouble = Double.parseDouble(amountFinanced);
        String amountFinancedFormatted = moneyFormatter.format(amountFinancedDouble);
        dealerTrackData.put("Text17", amountFinancedFormatted);

        // Term
        String loanTerm = (jse
                .executeScript("return (document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_terms')[0].value - 1)")
                .toString());
        dealerTrackData.put("Number Payments 4", dealerTrackData.get("buyerState").equals("CA") ? loanTerm
                : Integer.toString(Integer.parseInt(loanTerm) + 1));

        // Meaty Loan Calculations
        double aprDouble = (Double.parseDouble((String) dealerTrackData.get("Text15")) / (Double) 100.);
        int loanTermInt = Integer.parseInt(loanTerm) + 1;

        double monthlyPayment = Double.parseDouble(moneyFormatter.format(amountFinancedDouble
                * (aprDouble / 12.) / (1. - Math.pow(1. + aprDouble / 12., -loanTermInt))));
        String roundMonthlyPayment = moneyFormatter.format(monthlyPayment);

        double totalOfPayments = monthlyPayment * loanTermInt;
        String roundTotalOfPayments = moneyFormatter.format(totalOfPayments);

        // Total of Payments
        dealerTrackData.put("Text18", roundTotalOfPayments);

        // Finance Charge (take care of down payment later)
        dealerTrackData.put("Text16", moneyFormatter.format(totalOfPayments - amountFinancedDouble));

        // Monthly Payments
        dealerTrackData.put("Text26", roundMonthlyPayment);
        dealerTrackData.put("Text31", roundMonthlyPayment);

        // First and Last Payment Date
        DateTimeFormatter ddFormat = DateTimeFormatter.ofPattern("M/d/yyyy");
        LocalDate dd = LocalDate.parse(args[2], ddFormat);
        int plusDays = (args[1].equals("Chase")) ? 45 : 30;

        LocalDate firstPayment = dd.plusDays(plusDays);
        LocalDate lastPayment = firstPayment.plusMonths(loanTermInt - 1);

        String firstPaymentFormatted = firstPayment.format(ddFormat);
        String lastPaymentFormatted = lastPayment.format(ddFormat);

        dealerTrackData.put("Text27", firstPaymentFormatted);
        dealerTrackData.put("Text32", lastPaymentFormatted);

        // Car Base Price
        String carBasePrice = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_price')[0].value");
        double carBasePriceDouble = Double.parseDouble(carBasePrice);
        String carBasePriceFormatted = moneyFormatter.format(carBasePriceDouble);

        dealerTrackData.put("Text33", carBasePriceFormatted);
        dealerTrackData.put("Text34", carBasePriceFormatted);

        // Sales Tax
        String carTaxes = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_sales_tax')[0].value");
        double carTaxesDouble = Double.parseDouble(carTaxes);
        String carTaxesFormatted = moneyFormatter.format(carTaxesDouble);

        dealerTrackData.put("Text49", carTaxesFormatted);

        // Extended Peace of Mind
        String serviceContract = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_warranty')[0].value");
        Double serviceContractDouble = 0.;

        if (!serviceContract.equals("")) {
            serviceContractDouble = Double.parseDouble(serviceContract);

            dealerTrackData.put("Text51", moneyFormatter.format(serviceContractDouble));
            // For California Contract
            dealerTrackData.put("Text94", "Beepi Peace of Mind");
            dealerTrackData.put("7/13_1LCompany", "Beepi Peace of Mind");
            // For Arizona or Texas Contract
            dealerTrackData.put("Beepi", "Beepi");
            dealerTrackData.put("na5", "Extended Peace of Mind");

        }

        // Documentary Service Fees
        String documentFee = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_other_finance_fees')[0].value");
        Double documentFeeDouble = 0.;

        if (!documentFee.equals("")) {
            documentFeeDouble = Double.parseDouble(documentFee);
            dealerTrackData.put("Text42", moneyFormatter.format(documentFeeDouble));
        }

        // Registration Fees
        String regFees = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_ttl')[0].value");
        double regFeesDouble = Double.parseDouble(regFees);
        String regFeesFormatted = moneyFormatter.format(regFeesDouble);

        dealerTrackData.put("Text62", regFeesFormatted);
        dealerTrackData.put("Text65", regFeesFormatted);

        // Calculate Contract Based on State
        switch ((String) dealerTrackData.get("buyerState")) {
        case "CA":
            californiaContract(args, jse, dealerTrackData, carBasePriceDouble, carTaxesDouble,
                    serviceContractDouble, regFeesDouble, documentFeeDouble, totalOfPayments);
            break;
        case "AZ":
        case "TX":
        case "WA":
            arizonaTexasWashingtonContract(args, jse, dealerTrackData, carBasePriceDouble, carTaxesDouble,
                    serviceContractDouble, regFeesDouble, documentFeeDouble, totalOfPayments);
            break;
        }

        // Amount Financed
        dealerTrackData.put("Text77", amountFinancedFormatted);

        // Delivery Date (Signatures)
        String ddFormatted = dd.format(ddFormat);

        dealerTrackData.put("Text159", ddFormatted);
        dealerTrackData.put("Text165", ddFormatted);

        if (cosigner)
            dealerTrackData.put("Text160", ddFormatted);

        // Populate Credit Applications
        if (args[1].equals("Ally"))
            getAllyCreditInfo(jse, dealerTrackData, cosigner);
        else
            getChaseCreditInfo(jse, dealerTrackData, driver);

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

    driver.quit();

    String contractDir = "DO NOT EDIT - AutoFill Contracts/";

    try {

        if (args[1].equals("Ally")) {
            outputDir = makeOutputDir(dealerTrackData);
            fillPdf(dealerTrackData, contractDir + "Blank Ally Credit Application.pdf", outputDir,
                    "Ally Credit Application");
            fillPdf(dealerTrackData, contractDir + "Blank Ally Odometer Disclosure.pdf", outputDir,
                    "Ally Odometer Disclosure");
            fillPdf(dealerTrackData, contractDir + "Blank Ally Insurance Form.pdf", outputDir,
                    "Ally Insurance Form");
            fillPdf(dealerTrackData, contractDir + "Ally Title Guarantee.pdf", outputDir, "Guarantee of Title");
        }

        else {
            fillPdf(dealerTrackData, contractDir + "Blank Agreement to Furnish Insurance.pdf", outputDir,
                    "Chase Insurance Form");
            fillPdf(dealerTrackData, contractDir + "Chase Title Guarantee.pdf", outputDir,
                    "Guarantee of Title");
        }

        switch ((String) dealerTrackData.get("buyerState")) {
        case "CA":
            fillPdf(dealerTrackData, contractDir + "Blank Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "AZ":
            fillPdf(dealerTrackData, contractDir + "Blank AZ Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "TX":
            fillPdf(dealerTrackData, contractDir + "Blank TX Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "WA":
            fillPdf(dealerTrackData, contractDir + "Blank WA Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        }

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

From source file:ToTrainingFolder.java

public static void main(String[] args) throws IOException {

    System.setProperty("webdriver.ie.driver",
            "C:\\Users\\Colin Cook\\Desktop\\Opstar Training Folder\\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();

    driver.get("http://10.0.1.53/opstar_test/");

    out.println("Launching Internet Explorer browser..");
    driver.manage().window().maximize();
    try {/* w  ww.  j av a 2 s .  c o  m*/
        Thread.sleep(1000); // pauses for 1 second
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    out.println("The title of the page being tested is:  " + driver.getTitle());

    WebElement acknowledge = driver
            .findElement(By.xpath("html/body/div[5]/div[1]/div[2]/div[2]/div[1]/div/div[2]/center/a"));
    acknowledge.click(); //first popup when you go on site
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement applications = driver.findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/a"));
    //driver.findElement(By.linkText("Training Folder"));
    System.out.println(applications.getText());
    applications.click();

    WebElement toTools = driver
            .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/a"));
    toTools.click();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement traingFolder = driver
            .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/ul/li/a"));
    traingFolder.click();
    System.out.println("The Training Folder has been selected");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeBox = driver.findElement(By.id("cboxClose"));
    closeBox.click(); //clicks second popup acknolwedge box
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement textBox = driver.findElement(By
            .xpath("html/body/div[3]/div[4]/div[2]/div/div[1]/div/div[2]/div/form/div/div/span/span[1]/span"));
    textBox.click();
    textBox.sendKeys("ken");
    textBox.sendKeys(Keys.ENTER);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    /***************
     THIS IS WHERE THE QUALIFICATIONS FOLDER STARTS
     ******************/

    WebElement image1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[1]/div[1]/span/a/img"));
    image1.click();
    image1.sendKeys(Keys.ESCAPE);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement table1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[1]/div[2]/input"));
    table1.clear();
    table1.sendKeys("Testing table 1, Opstar Test");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement date1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[1]/div[3]/input"));
    date1.click();
    date1.clear();
    date1.sendKeys("12/25/2016");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    // WebElement save = driver.findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[1]/div[5]/span[1]/i"));
    //save.click();

    WebElement image2 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[3]/div[1]/span/a/img"));
    image2.click();
    image2.sendKeys(Keys.ESCAPE);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement title2 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[3]/div[2]/input"));
    title2.clear();
    title2.sendKeys("Testing table 2, Opstar test 2");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement date2 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[3]/div[3]/input"));
    date2.click();
    date2.clear();
    date2.sendKeys("01/01/2017");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    // WebElement save2 = driver.findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[2]/div[3]/div[3]/div[3]/div[5]/span[1]/i"));
    //save2.click();

    WebElement closeQualifications = driver
            .findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[1]/div/a[2]"));
    closeQualifications.click();

    System.out.println("The Qualifications folder has been tested");

    /***************
     THIS IS WHERE THE DESIGNATIONS FOLDER STARTS
     ******************/

    WebElement Designations = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    Designations.click();
    Designations.sendKeys(Keys.ESCAPE);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement DesignationsTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/table/tbody/tr/td[2]/input"));
    DesignationsTitle.clear();
    DesignationsTitle.sendKeys("Testing the Desiganations title box, Opstar Test");

    WebElement DesignationsIssue = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/table/tbody/tr/td[3]/input"));

    DesignationsIssue.clear();
    DesignationsIssue.sendKeys("03/24/2017");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    // WebElement saveDesignations = driver.findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/table/tbody/tr/td[5]/span[1]/i"));
    //saveDesignations.click();

    WebElement closeDesignations = driver
            .findElement(By.xpath(".//*[@id='student_folder_wrapper']/div[2]/div[1]/div/div[1]/div/a[2]"));
    closeDesignations.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    System.out.println("The Designations box has been tested");

    /***************
     THIS IS WHERE THE WAIVERS FOLDER STARTS
     ******************/

    WebElement waivers = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/div/a[2]"));
    waivers.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement waiversFile = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    waiversFile.click();
    waiversFile.sendKeys(Keys.ESCAPE);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement waiversTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/table/tbody/tr/td[2]/input"));
    waiversTitle.clear();
    waiversTitle.sendKeys("Testing the Waivers folder, Opstar test");

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement issueDateWaivers = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/table/tbody/tr/td[3]/input"));
    issueDateWaivers.clear();
    issueDateWaivers.sendKeys("01/16/2016");

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    //WebElement saveWaivers = driver.findElement(By.xpath(".//*[@id='student_folder_wrapper']/div[2]/div[2]/div/div[2]/table/tbody/tr/td[5]/span[1]/i"));
    //saveWaivers.click();

    WebElement closeWaivers = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/div/a[2]"));
    closeWaivers.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    System.out.println("The waivers folder has been tested");
    /***************
     THIS IS WHERE THE PROFESSIONAL LICENSES FOLDER STARTS
     ******************/

    WebElement proLicensesCert = driver
            .findElement(By.xpath(".//*[@id='student_folder_wrapper']/div[2]/div[3]/div/div[1]/div/a[2]"));
    proLicensesCert.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement imagePro = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    imagePro.click();
    imagePro.sendKeys(Keys.ESCAPE);

    WebElement proTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[2]/table/tbody/tr/td[2]/input"));
    proTitle.clear();
    proTitle.sendKeys("OpSTAR Automation testing this title box");

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement proIssueDate = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[2]/table/tbody/tr/td[3]/input"));
    proIssueDate.clear();
    proIssueDate.sendKeys("05/04/2017");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement proClose = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[1]/div/a[2]"));
    proClose.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    System.out.println("The professional Licenses, Certificates, Medical folder has been tested");
    /***************
     THIS IS WHERE THE FIRSTAID FOLDER STARTS
     ******************/

    WebElement firstAid = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[1]/div/a[2]"));
    firstAid.click();

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement firstAidImage = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    firstAidImage.click();
    firstAidImage.sendKeys(Keys.ESCAPE);

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement firstAidTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[2]/table/tbody/tr/td[2]/input"));
    firstAidTitle.clear();
    firstAidTitle.sendKeys("KeyBridge automation testing using Selenium");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement firstAidDate = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[2]/table/tbody/tr/td[3]/input"));
    firstAidDate.clear();
    firstAidDate.sendKeys("02/02/2017");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeFirstAid = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[1]/div/a[2]"));
    closeFirstAid.click();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    System.out.println("The First Aid folder has been tested");
    /***************
     THIS IS WHERE THE STAR FOLDER STARTS
     ******************/

    WebElement starOpen = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[1]/div/a[2]"));
    starOpen.click();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement starImage1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[2]/table/tbody/tr[1]/td[1]/span/a/img"));
    starImage1.click();
    starImage1.sendKeys(Keys.ESCAPE);

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement starTitle1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[2]/table/tbody/tr[1]/td[2]/input"));
    starTitle1.clear();
    starTitle1.sendKeys("KeyBridge OpSTAR automation testing");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement starIssueDate1 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[2]/table/tbody/tr[1]/td[3]/input"));
    starIssueDate1.clear();
    starIssueDate1.sendKeys("03/17/2017");

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement starTitle2 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[2]/table/tbody/tr[2]/td[2]/input"));
    starTitle2.clear();
    starTitle2.sendKeys("CPB Automation Testing");

    // WebElement starIssueDate2 = driver.findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[2]/table/tbody/tr[2]/td[3]/input"));
    // starIssueDate2.click();

    WebElement closeStarFolder = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[1]/div/a[2]"));
    closeStarFolder.click();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    System.out.println("The Star Folder has been tested");

    /***************
     THIS IS WHERE THE TRAINING COURSES AND TESTS FOLDER STARTS
     ******************/
    WebElement openCourseAndTests = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/div/a[2]"));
    openCourseAndTests.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement lastFive = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/h4/span[2]"));
    lastFive.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement showAll = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/h4/span[3]"));
    showAll.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeTrainingCourse = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/div/a[2]"));
    closeTrainingCourse.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    System.out.println("The Training Courses and Tests folder has been tested");
    /***************
     THIS IS WHERE THE PROFESSIONAL DEVELOPMENT FOLDER STARTS
     ******************/

    WebElement proDevelopment = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[1]/div/a[2]"));
    proDevelopment.click();

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement proImage = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    proImage.click();
    proImage.sendKeys(Keys.ESCAPE);

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement proTitle2 = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[2]/table/tbody/tr/td[2]/input"));
    proTitle2.clear();
    proTitle2.sendKeys("Testing the PRO Development box");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement proDevelopmentDate = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[2]/table/tbody/tr/td[3]/input"));
    proDevelopmentDate.clear();
    proDevelopmentDate.sendKeys("03/24/2017");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeProDevelopment = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[1]/div/a[2]"));
    closeProDevelopment.click();

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    System.out.println("The Professional Development / Individual Development Plan Folder has been tested");
    /***************
     THIS IS WHERE THE FLETC CERTIFICATES FOLDER STARTS
     ******************/

    WebElement fletcOpen = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[1]/div/a[2]"));
    fletcOpen.click();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement fletcImage = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    fletcImage.click();
    fletcImage.sendKeys(Keys.ESCAPE);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement fletcTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[2]/table/tbody/tr/td[2]/input"));
    fletcTitle.clear();
    fletcTitle.sendKeys("Testing the FLETC Certificates folder");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement fletcDate = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[2]/table/tbody/tr/td[3]/input"));
    fletcDate.clear();
    fletcDate.sendKeys("03/24/2017");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement closeFLETC = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[1]/div/a[2]"));
    closeFLETC.click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    System.out.println("The FLETC Certificates Folder has been tested");
    /***************
     THIS IS WHERE THE MISCELLANEOUS CERTIFICATES FOLDER STARTS
     ******************/

    WebElement openMisc = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[1]/div/a[2]"));
    openMisc.click();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

    WebElement miscImage = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[2]/table/tbody/tr/td[1]/span/a/img"));
    miscImage.click();
    miscImage.sendKeys(Keys.ESCAPE);

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement miscTitle = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[2]/table/tbody/tr/td[2]/input"));
    miscTitle.clear();
    miscTitle.sendKeys("Testing the the Misc box");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement miscDate = driver.findElement(By.xpath(
            "html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[2]/table/tbody/tr/td[3]/input"));
    miscDate.clear();
    miscDate.sendKeys("12/25/2016");

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    WebElement closeMisc = driver.findElement(
            By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[1]/div/a[2]"));
    closeMisc.click();
    System.out.println("The Miscellaneous folder has been tested");

    System.out.println("The Training Folder automation test has successfully passed!");

}

From source file:facets_testing.java

public void wp_login() {
    WebDriver driver = new ChromeDriver();
    try {//  w w w .  jav  a2s. co  m
        driver.get(wordpress_url);
        driver.findElement(By.id("user_login")).sendKeys(username);
        driver.findElement(By.id("user_pass")).sendKeys(password);
        driver.findElement(By.id("wp-submit")).click();
    } catch (Exception e) {
        System.out.println("Exception produced when logging into wp-admin. Error is: " + e);
    }
}

From source file:seleniumTester.java

@Test
public void test1() {
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));

        return rows.size() == 5;
    });//w  w w . j a v  a2  s . co m
}