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:facets_testing.java

@Test
public void testCreationYearUndoFiltering() {
    driver.setJavascriptEnabled(true);//from www.j  a v a2  s  . c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        driver.findElement(By.xpath("//div[@id=\"drs_creation_year_sim\"]/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("Creation Year unfiltering is not working.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testSubjectFacet() {
    driver.setJavascriptEnabled(true);/*from  w w  w  .j a v a 2 s.com*/
    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:facets_testing.java

@Test
public void testSubjectLinkPresent() {
    List<String> subject_names = new ArrayList<>();
    driver.setJavascriptEnabled(true);//from  w w w .j  av  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, JUnitMatchers.hasItem("Youth"));
    } catch (Exception e) {
        System.out.println("Subject is not present.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testSubjectLinkNotPresent() {
    List<String> subject_names = new ArrayList<>();
    driver.setJavascriptEnabled(true);//from  w  w w  .  j a  v  a 2s  . co  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:facets_testing.java

@Test
public void testSubjectMoreButton() {
    driver.setJavascriptEnabled(true);/*from w w  w  .j  a va  2 s .c  om*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String element_text = driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/button"))
                .getText();
        System.out.println(
                driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/button")).getText());
        assertEquals(element_text, "More Subjects");
    } catch (Exception e) {
        System.out.println("More Subjects button is not present.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testSubjectMoreButtonWorking() {
    driver.setJavascriptEnabled(true);//from  w ww  .  j av  a 2  s . c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/button")).click();
        WebElement more_subject_model = driver.findElement(By.xpath("//div[@id=\"drs_modal_subject_sim\"]"));
        assertTrue(more_subject_model.isEnabled());
    } catch (Exception e) {
        System.out.println("More Subjects button is not working.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testSubjectFiltering() {
    driver.setJavascriptEnabled(true);// www  . j  a v a2  s . c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String facet_name = driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[1]/b"))
                .getText();
        String facet_text = driver
                .findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/div/div[2]/a[1]/div[1]")).getText();
        driver.findElement(By.xpath("//div[@id=\"drs_subject_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("Subject filtering is not working.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testSubjectUndoFiltering() {
    driver.setJavascriptEnabled(true);//from w  ww. j  ava2 s .c  o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        driver.findElement(By.xpath("//div[@id=\"drs_subject_sim\"]/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("Subject unfiltering is not working.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testDepartmentFacet() {
    driver.setJavascriptEnabled(true);/*from  ww w . jav a  2 s. c  om*/
    try {
        driver.get(page_url);
        //            Thread.sleep(14);
        String element_text = driver
                .findElement(By.xpath("//div[@id=\"drs_drs_department_ssim\"]/div/div[1]/b")).getText();
        System.out.println(
                driver.findElement(By.xpath("//div[@id=\"drs_drs_department_ssim\"]/div/div[1]/b")).getText());
        assertEquals(element_text, "Department");
    } catch (Exception e) {
        System.out.println("Department facet not found. Error : " + e);
        fail();
    }
}

From source file:facets_testing.java

@Test
public void testDepartmentLinkPresent() {
    List<String> dept_names = new ArrayList<>();
    driver.setJavascriptEnabled(true);/*  w  w w .jav a 2 s  .c  o  m*/
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> dept_list = driver
                .findElements(By.xpath("//div[@id=\"drs_drs_department_ssim\"]/div/div[2]/a/div[1]"));
        for (WebElement dept : dept_list) {
            dept_names.add(dept.getText());
        }
        assertThat(dept_names, JUnitMatchers.hasItem("School of Education"));
    } catch (Exception e) {
        System.out.println("Department is not present.Error : " + e);
    }
}