Example usage for org.openqa.selenium By xpath

List of usage examples for org.openqa.selenium By xpath

Introduction

In this page you can find the example usage for org.openqa.selenium By xpath.

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:facetsTest.java

@Test
public void testTitleLinkNotPresent() {
    List<String> title_names = new ArrayList<String>();
    HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.BEST_SUPPORTED);
    driver.setJavascriptEnabled(true);/*from   w  ww  .j  a v a2s  . com*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> title_list = driver
                .findElements(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[2]/a/div[1]"));
        for (WebElement title : title_list) {
            title_names.add(title.getText());
        }
        assertThat(title_names, not(JUnitMatchers.hasItem("abcdef")));
    } catch (Exception e) {
        System.out.println("Title is falsely present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testTitleFiltering() {
    driver.setJavascriptEnabled(true);//from  www .  j a v  a2  s. c o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String facet_name = driver
                .findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[1]/b")).getText();
        String facet_text = driver
                .findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[2]/a[1]/div[1]"))
                .getText();
        driver.findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[2]/a[1]/div[1]")).click();
        String filter_text = driver.findElement(By.xpath("//div[@id=\"drs-selection\"]/a[1]")).getText();
        assertEquals(filter_text, facet_name + " > " + facet_text);
    } catch (Exception e) {
        System.out.println("Title filtering is not working.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testTitleUndoFiltering() {
    driver.setJavascriptEnabled(true);// w  w  w. j  ava  2 s .c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        driver.findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[2]/a[1]/div[1]")).click();
        driver.findElement(By.xpath("//div[@id=\"drs-selection\"]/a/span"));
        driver.findElement(By.xpath("//div[@id=\"drs-selection\"]/a/span")).click();
        String finder = driver.findElement(By.xpath("//div[@id=\"drs-selection\"]")).getText();
        assertEquals(finder, "");
    } catch (Exception e) {
        System.out.println("Title unfiltering is not working.Error : " + e);
    }
}

From source file:StateContentTest.java

public void testFAQPage(String state) throws InterruptedException {
    driver.findElement(By.linkText("FAQs")).click();

    /*Test "How Long is this course" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[6]/div/h3/span")).click();
    Thread.sleep(300);/*from   w w  w. j a  v  a  2s  .c om*/
    assertEquals(copyMatrix.get(state)[1].trim(),
            driver.findElement(By.cssSelector("#collapse6 > div.panel-body > p")).getText().trim());

    /*Test "Can I start the online version of the AARP Smart Driver course at a computer in one location and continue at another?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[7]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[2].trim(),
            driver.findElement(By.cssSelector("#collapse7 > div.panel-body > p")).getText().trim());

    /*Test "How do I navigate the online course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[8]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[7].trim(),
            driver.findElement(By.cssSelector("#collapse8 > div.panel-body")).getText().trim());

    /*Test "Is this online version of the AARP Smart Driver course narrated or just text?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[9]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[8].trim(),
            driver.findElement(By.cssSelector("#collapse9 > div.panel-body > p")).getText().trim());

    /*Test "Quizzes and Exams: Will those be recorded and graded? Can I fail the course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[10]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[9].trim(),
            driver.findElement(By.cssSelector("#collapse10 > div.panel-body")).getText().trim());

    /*Test "What is the cost of the course and how do I pay" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[1]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[13].trim(),
            driver.findElement(By.cssSelector("#collapse1 > div.panel-body")).getText().trim());

    /*Test "Is it safe to send my credit card information over the internet?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[2]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[14].trim(),
            driver.findElement(By.cssSelector("#collapse2 > div.panel-body")).getText().trim());

    /*Test "What information do I need handy for registering?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[4]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[15].trim(),
            driver.findElement(By.cssSelector("#collapse4 > div.panel-body")).getText().trim());

    /*Test "Why does AARP Driver Safety ask for my driver's license number and date of birth when I register for the AARP Smart Driver course?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[5]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[16].trim(),
            driver.findElement(By.cssSelector("#collapse5 > div.panel-body")).getText().trim());

    /*Test "If I can't finish the course or don't wish to continue it, will I be able to receive a refund?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[3]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[17].trim(),
            driver.findElement(By.cssSelector("#collapse3 > div.panel-body")).getText().trim());

    /*Test "System Requirements for taking the AARP Smart Driver course online:" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[13]/div/h3/span")).click();
    Thread.sleep(300);
    driver.findElement(By.cssSelector("span.sys-link")).click();
    assertEquals(copyMatrix.get(state)[18].trim(),
            driver.findElement(By.cssSelector("#collapse13 > div.panel-body")).getText().trim());

    /*Test "What happens if I get disconnected?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[11]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[19].trim(),
            driver.findElement(By.cssSelector("#collapse11 > div.panel-body")).getText().trim());

    /*Test "What happens if I have problems while taking the course or the system malfunctions for any reason?" content*/
    driver.findElement(By.xpath("//div[@id='accordion']/div[12]/div/h3/span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[20].trim(),
            driver.findElement(By.cssSelector("#collapse12 > div.panel-body")).getText().trim());
}

From source file:StateContentTest.java

public void testWhyTakePage(String state) {
    driver.findElement(By.xpath("//a[contains(text(),'Why Take Our Course?')]")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.cssSelector("div.state-holder > p")).getText().trim());
}

From source file:StateContentTest.java

public void testPricingPage(String state) {
    driver.findElement(By.xpath("//a[contains(text(),'Pricing')]")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.cssSelector("div.course-text")).getText().trim());
}

From source file:StateContentTest.java

public void testSignUpPage(String state) throws InterruptedException {
    driver.findElement(By.cssSelector("a.btn.btn-primary")).click();

    assertEquals(copyMatrix.get(state)[4].trim(),
            driver.findElement(By.id("courseReasonDesc")).getText().trim());

    driver.findElement(By.id("confirmState")).click();
    Thread.sleep(300);/* ww w  .ja  v a  2 s  . c  o m*/

    switch (state) {
    case "Alaska":
    case "California":
    case "Delaware":
    case "District of Columbia":
    case "Michigan":
    case "Minnesota":
    case "Pennsylvania":
    case "West Virginia":
        assertEquals(copyMatrix.get(state)[5].trim(),
                driver.findElement(By.id("id=REFRESHER-Q")).getText().trim());
        driver.findElement(By.xpath("(//a[contains(text(),'?')])[3]")).click();
        Thread.sleep(300);
        assertEquals(copyMatrix.get(state)[6].trim(),
                driver.findElement(By.id("id=REFRESHER-TIP")).getText().trim());
        driver.findElement(By.cssSelector(
                "#refresherpop > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close"))
                .click();

        new Select(driver.findElement(By.id("DLTYPE"))).selectByVisibleText("CLASS A");
        new Select(driver.findElement(By.id("COURSEREASON"))).selectByVisibleText("Court Referral");
    default:
        driver.findElement(By.id("continueCourseOptions")).click();
        break;
    }
    Thread.sleep(300);

    driver.findElement(By.id("CCNAME")).clear();
    driver.findElement(By.id("CCNAME")).sendKeys("test test");
    driver.findElement(By.id("cc")).clear();
    driver.findElement(By.id("cc")).sendKeys("4111111111111111");
    new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)");
    new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018");
    driver.findElement(By.id("CCCVV")).clear();
    driver.findElement(By.id("CCCVV")).sendKeys("0000");
    driver.findElement(By.id("CCEMAIL")).clear();
    driver.findElement(By.id("CCEMAIL")).sendKeys("kyle.erickson@thomasarts.com");
    driver.findElement(By.id("CCCEMAIL")).clear();
    driver.findElement(By.id("CCCEMAIL")).sendKeys("kyle.erickson@thomasarts.com");
    driver.findElement(By.id("PASSWORD")).clear();
    driver.findElement(By.id("PASSWORD")).sendKeys("password1");
    driver.findElement(By.id("CPASSWORD")).clear();
    driver.findElement(By.id("CPASSWORD")).sendKeys("password1");
    driver.findElement(By.id("TERMS")).click();
    driver.findElement(By.id("coursePurchase")).click();

    Thread.sleep(300);
    //assertEquals("Thank you for your purchase!", driver.findElement(By.cssSelector("h1")).getText());

    //      driver.findElement(By.id("FIRSTNAME")).clear();
    //      driver.findElement(By.id("FIRSTNAME")).sendKeys("test");
    //      driver.findElement(By.id("LASTNAME")).clear();
    //      driver.findElement(By.id("LASTNAME")).sendKeys("test");
    //      driver.findElement(By.id("ADDRESS1")).clear();
    //      driver.findElement(By.id("ADDRESS1")).sendKeys("555 fake st.");
    //      driver.findElement(By.id("CITY")).clear();
    //      driver.findElement(By.id("CITY")).sendKeys("faketown");
    //      driver.findElement(By.id("ZIP")).clear();
    //      driver.findElement(By.id("ZIP")).sendKeys("84015");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_MONTH"))).selectByVisibleText("MAY");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_DAY"))).selectByVisibleText("4");
    //      new Select(driver.findElement(By.id("DATEOFBIRTH_YEAR"))).selectByVisibleText("1915");
    //      driver.findElement(By.id("radio")).click();
    //      driver.findElement(By.id("PHONE")).clear();
    //      driver.findElement(By.id("PHONE")).sendKeys("555-555-5555");
    //      driver.findElement(By.id("DL")).clear();
    //      driver.findElement(By.id("DL")).sendKeys("555555555");
    //      driver.findElement(By.name("submit")).click();
}

From source file:StateContentTest.java

public void testGiftPaymentPage(String state) throws InterruptedException {
    loadPage(false);// ww  w.j  a v a  2s. c  om
    driver.findElement(By.xpath("//a[contains(text(),'Purchase the course as a gift')]")).click();

    driver.findElement(By.cssSelector("p.sta-link > a > span")).click();
    Thread.sleep(300);
    assertEquals(copyMatrix.get(state)[21].trim(),
            driver.findElement(By.cssSelector(
                    "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-body > p")).getText()
                    .trim());
    driver.findElement(By.cssSelector(
            "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close"))
            .click();
    Thread.sleep(300);
    driver.findElement(By.id("confirmState")).click();

    driver.findElement(By.id("RNAME")).clear();
    driver.findElement(By.id("RNAME")).sendKeys("Test Test");
    driver.findElement(By.id("REMAIL")).clear();
    driver.findElement(By.id("REMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("CREMAIL")).clear();
    driver.findElement(By.id("CREMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("FROMANME")).clear();
    driver.findElement(By.id("FROMANME")).sendKeys("test");
    driver.findElement(By.id("continueCourseOptions")).click();

    driver.findElement(By.id("CCNAME")).clear();
    driver.findElement(By.id("CCNAME")).sendKeys("test");
    driver.findElement(By.id("cc")).clear();
    driver.findElement(By.id("cc")).sendKeys("4111111111111111");
    new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)");
    new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018");
    driver.findElement(By.id("CCCVV")).clear();
    driver.findElement(By.id("CCCVV")).sendKeys("0000");
    driver.findElement(By.id("CCEMAIL")).clear();
    driver.findElement(By.id("CCEMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("CCCEMAIL")).clear();
    driver.findElement(By.id("CCCEMAIL")).sendKeys("test@test.test");
    driver.findElement(By.id("TERMS")).click();
    driver.findElement(By.id("coursePurchase")).click();

    Thread.sleep(3000);

    assertEquals("Thank you for your gift purchase!", driver.findElement(By.cssSelector("h1")).getText());
}

From source file:SamlLoginAcceptanceTests.java

License:Open Source License

private void samlPhpLogin(String linkText) {
    webDriver.get(baseUrl + "/login");
    Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
    webDriver.findElement(By.xpath("//a[text()='" + linkText + "']")).click();
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys("marissa");
    webDriver.findElement(By.name("password")).sendKeys("koala");
    webDriver.findElement(By.xpath("//input[@value='Login']")).click();
    assertEquals("marissa@test.org",
            webDriver.findElement(By.xpath("//div[@class='dropdown-trigger']")).getText());
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
}

From source file:TestaCadastroProcesso.java

@Test(dependsOnGroups = "salva", groups = "salvou")
public void testaSeInseriuProcesso() throws Exception {

    driver.navigate()//from  ww w. j a  v  a 2  s. c  o m
            .to("http://52.1.49.37/SIAPCON_SPRINT11/ListarProcessos.jsf?(Not.Licensed.For.Production)=");

    try {

        // insere orgao do processo na busca
        WebElement orgao = driver
                .findElement(By.id("RichWidgets_wt88:wtMainContent:wtnumeroProcessoOrgaoWidget"));
        orgao.sendKeys(proc.substring(0, 5));

        // insere numero do processo na busca
        WebElement numero = driver
                .findElement(By.id("RichWidgets_wt88:wtMainContent:wtnumeroProcessoNumeroWidget"));
        numero.sendKeys(proc.substring(5, 11));

        // insere ano do processo na busca
        WebElement ano = driver.findElement(By.id("RichWidgets_wt88:wtMainContent:wtnumeroProcessoAnoWidget"));
        ano.sendKeys(proc.substring(11, 13));

        // acha o input do submit e clica para fazer a pesquisa
        WebElement submit3 = driver.findElement(By.xpath("//input[@type='submit']"));
        submit3.click();

        // para esperar a resposta do Ajax impede o Selenium de prosseguir
        Thread.sleep(60000);

        WebElement table = driver.findElement(By.id("RichWidgets_wt88:wtMainContent:wtProcessoTableAjaxRfrsh"));

        WebElement a = driver.findElement(By.id("RichWidgets_wt88:wtMainContent:wtProcessoTable:0:wt7"));

        String processo = proc.substring(0, 5) + "." + proc.substring(5, 11) + "/" + proc.substring(11, 13);

        if (!a.getText().toString().contains(processo)) {
            Assert.fail("No cadastrou!");
        }

    } catch (Exception e) {
        throw (e);
    }
}