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 testCreatorLinkPresent() {
    List<String> creator_name = new ArrayList<String>();
    driver.setJavascriptEnabled(true);//from ww w . j  a v  a 2  s .c  o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creator_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement creator : creator_list) {
            creator_name.add(creator.getText());
        }
        assertThat(creator_name, JUnitMatchers.hasItem("Shwachman, Irene"));
    } catch (Exception e) {
        System.out.println("Creator name is not present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testCreatorLinkNotPresent() {
    List<String> creator_name = new ArrayList<String>();
    driver.setJavascriptEnabled(true);//from   ww w  . jav  a2s. c  o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creator_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement creator : creator_list) {
            creator_name.add(creator.getText());
        }
        assertThat(creator_name, not(JUnitMatchers.hasItem("abcdef")));
    } catch (Exception e) {
        System.out.println("Creator name is falsely present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testCreationYearLinkPresent() {
    List<String> creator_years = new ArrayList<String>();
    driver.setJavascriptEnabled(true);/*  w w w .j  av a  2  s  .c o  m*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creation_years_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creation_year_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement year : creation_years_list) {
            creator_years.add(year.getText());
        }
        assertThat(creator_years, JUnitMatchers.hasItem("1958"));
    } catch (Exception e) {
        System.out.println("Creation year is not present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testCreationYearLinkNotPresent() {
    List<String> creator_years = new ArrayList<String>();
    driver.setJavascriptEnabled(true);//  ww w  . j a  v  a 2  s  .c  o  m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creation_years_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creation_year_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement year : creation_years_list) {
            creator_years.add(year.getText());
        }
        assertThat(creator_years, not(JUnitMatchers.hasItem("20000")));
    } catch (Exception e) {
        System.out.println("Creation year is falsely present.Error : " + e);
    }
}

From source file:facetsTest.java

public void testCreationYearFiltering() {
    driver.setJavascriptEnabled(true);//from   w ww .java2s .c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String facet_name = driver.findElement(By.xpath("//div[@id=\"drs_creation_year_sim\"]/div/div[1]/b"))
                .getText();
        String facet_text = driver
                .findElement(By.xpath("//div[@id=\"drs_creation_year_sim\"]/div/div[2]/a[1]/div[1]")).getText();
        driver.findElement(By.xpath("//div[@id=\"drs_creation_year_sim\"]/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("Creation Year filtering is not working.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testSubjectFacet() {
    driver.setJavascriptEnabled(true);//www. j  a  v a  2s . co  m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String element_text = driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[1]/b"))
                .getText();
        System.out
                .println(driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[1]/b")).getText());
        assertEquals(element_text, "Subject");
    } catch (Exception e) {
        System.out.println("Subject facet not found. Error : " + e);
        fail();
    }
}

From source file:facetsTest.java

@Test
public void testSubjectLinkPresent() {
    List<String> subject_names = new ArrayList<String>();
    driver.setJavascriptEnabled(true);/*from w  w w. ja v  a  2 s. c o m*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> subjects_list = driver
                .findElements(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement subject : subjects_list) {
            subject_names.add(subject.getText());
        }
        assertThat(subject_names, JUnitMatchers.hasItem("Youth"));
    } catch (Exception e) {
        System.out.println("Subject is not present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testSubjectLinkNotPresent() {
    List<String> subject_names = new ArrayList<String>();
    driver.setJavascriptEnabled(true);/*from w w  w  .  ja  v a2  s.c  o m*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> subjects_list = driver
                .findElements(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement subject : subjects_list) {
            subject_names.add(subject.getText());
        }
        assertThat(subject_names, not(JUnitMatchers.hasItem("abcdef")));
    } catch (Exception e) {
        System.out.println("Subject is falsely present.Error : " + e);
    }
}

From source file:facetsTest.java

@Test
public void testTitleFacet() {
    driver.setJavascriptEnabled(true);/*  ww w .  j av  a2  s .com*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String element_text = driver
                .findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[1]/b")).getText();
        System.out.println(driver.findElement(By.xpath("//div[@id=\"drs_drs_course_title_ssim\"]/div/div[1]/b"))
                .getText());
        assertEquals(element_text, "Course Title");
    } catch (Exception e) {
        System.out.println("Course Title facet not found. Error : " + e);
        fail();
    }
}

From source file:facetsTest.java

@Test
public void testTitleLinkPresent() {
    List<String> title_names = new ArrayList<String>();
    driver.setJavascriptEnabled(true);/*from  ww w.j  av  a 2s.  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, JUnitMatchers.hasItem("Basic Composition"));
    } catch (Exception e) {
        System.out.println("Title is not present.Error : " + e);
    }
}