Example usage for org.openqa.selenium WebElement findElements

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java

@Test
@RunAsClient/* w  w  w .  j a  v  a2 s.  co m*/
public void t1createCountry() throws InterruptedException {
    Thread.sleep(1500);
    boolean success = false;
    driver.findElement(By.partialLinkText("Country")).click();
    Thread.sleep(3000);
    driver.findElement(By.id("createBtn")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Colombia");
    driver.findElement(By.id("population")).clear();
    driver.findElement(By.id("population")).sendKeys("80000000");
    driver.findElement(By.id("saveBtn")).click();
    Thread.sleep(2000);
    List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    for (WebElement webElement : rows) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("Colombia") && elems.get(1).getText().equals("80000000")) {
            success = true;
        }
    }
    assertTrue(success);
    Thread.sleep(1000);
}

From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java

@Test
@RunAsClient/*from  w  w w. j ava2s.  com*/
public void t2createSport() throws Exception {
    boolean success = false;
    driver.findElement(By.partialLinkText("Sport")).click();
    Thread.sleep(3000);
    driver.findElement(By.id("createBtn")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Futbol");
    driver.findElement(By.id("minAge")).clear();
    driver.findElement(By.id("minAge")).sendKeys("3");
    driver.findElement(By.id("maxAge")).clear();
    driver.findElement(By.id("maxAge")).sendKeys("90");
    driver.findElement(By.id("rules")).clear();
    driver.findElement(By.id("rules")).sendKeys("No rules");
    Select contries = new Select(driver.findElement(By.id("country")));
    contries.selectByVisibleText("Colombia");
    driver.findElement(By.id("saveBtn")).click();
    Thread.sleep(3000);
    List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    for (WebElement webElement : rows) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) {
            success = true;
        }
    }
    assertTrue(success);
    Thread.sleep(1000);
}

From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java

@Test
@RunAsClient//from w  w w .  j  a va 2s. c o m
public void t3deleteSport() throws Exception {
    boolean success = false;
    driver.findElement(By.partialLinkText("Sport")).click();
    Thread.sleep(3000);
    List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    for (WebElement webElement : rows) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) {
            List<WebElement> buttons = elems.get(6).findElements(By.xpath("button"));
            buttons.get(1).click();
            success = true;
            break;
        }
    }
    Thread.sleep(3000);
    //Se busca el objeto que fue eliminado, si se encuentra hay error al eliminar
    rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    if (rows.size() > 0) {
        for (WebElement webElement : rows) {
            List<WebElement> elems = webElement.findElements(By.xpath("td"));
            if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) {
                success = false;
                break;
            }
        }
    }

    Thread.sleep(1000);
    assertTrue(success);
}

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

@Test
public void testUpdateSport() throws Exception {
    driver.get(baseUrl + "/ClinicaDeProblemas.web/comentario.html");
    //    driver.findElement(By.linkText("Proyectos")).click();
    //Se hace clic en  el vinculo "Edit" del primer elemento de la lista de sports (el elemento que se cre en la anterior prueba)
    driver.findElement(By.linkText("Editar")).click();
    Thread.sleep(2000);/*w  w  w  .ja v a2 s  . c om*/
    //Se realiza el mismo proceso de diligenciamento de los campos con los cambios
    driver.findElement(By.id("name")).clear();
    ;
    driver.findElement(By.id("name")).sendKeys("coment1");
    driver.findElement(By.id("contenido")).clear();
    driver.findElement(By.id("contenido")).sendKeys("contenido1");
    driver.findElement(By.id("login")).clear();
    driver.findElement(By.id("login")).sendKeys("login1");

    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    //Se verifica que en la lista de respuesta hallan aparecido los cambios en el elemento y tambin el mensaje de edicin exitosa.
    WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));

        if (elems.get(0).getText().equals("coment1")) {
            fail = true;
        }

    }
    //  driver.findElement(By.linkText("Proyectos")).click();
    /**
     * Comando que realiza click sobre el boton "create" del toolbar. La
     * funcin 'find' encuentra el control y posteriormente hace clic en el
     * mismo. La forma en la que se busca el control es utilizando
     * expresiones xPath ya que los id de los mismos nunca son iguales (se
     * generan con junto con el valor de componentId que vara).
     */
    driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();

    /**
     * Comando que duerme el Thread del test por 2 segundos para dejar que
     * el efecto 'slide down' de backbone abra el formulario de createSport.
     */
    Thread.sleep(2000);

    /**
     * Comando que busca el elemento 'name' en el html actual.
     * Posteriormente limpia su contenido (comando clean).
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("coment1");
    driver.findElement(By.id("contenido")).clear();
    driver.findElement(By.id("contenido")).sendKeys("contenido1");
    driver.findElement(By.id("login")).clear();
    driver.findElement(By.id("login")).sendKeys("login1");

    Thread.sleep(2000);
    Thread.sleep(2000);
    Thread.sleep(2000);

    List<WebElement> a = driver.findElements(By.xpath("//button[contains(@id,'create')]"));
    a.get(1).click();
    Thread.sleep(2000);
    Thread.sleep(2000);
    // driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();
    List<WebElement> b = driver.findElements(By.id("name"));
    b.get(1).sendKeys("hola");
    // driver.findElement(By.id("name")).sendKeys("emprendimiento");
    Thread.sleep(2000);

    /**
     * Comando que encuentra y hace clic sobre el boton "Save" del toolbar
     * (una vez mas encontrado por una expresin Xpath)
     */
    List<WebElement> c = driver.findElements(By.xpath("//button[contains(@id,'save')]"));
    c.get(1).click();
    c.get(0).click();

}

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

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

        }

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

}

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

@Test
public void testUpdateOpinion() throws Exception {
    driver.get(baseUrl + "/ClinicaDeProblemas.web/opinion.html");
    //    driver.findElement(By.linkText("Proyectos")).click();
    //Se hace clic en  el vinculo "Edit" del primer elemento de la lista de sports (el elemento que se cre en la anterior prueba)
    driver.findElement(By.linkText("Editar")).click();
    Thread.sleep(2000);/*from w  w w  .  ja v a2  s . co m*/
    //Se realiza el mismo proceso de diligenciamento de los campos con los cambios
    driver.findElement(By.id("name")).sendKeys("opinion1");
    driver.findElement(By.id("contenido")).clear();
    driver.findElement(By.id("contenido")).sendKeys("contenido1");
    driver.findElement(By.id("calificacion")).clear();
    driver.findElement(By.id("calificacion")).sendKeys("calificacion1");
    driver.findElement(By.id("dificultadEjercicios")).clear();
    driver.findElement(By.id("dificultadEjercicios")).sendKeys("dificultad1");
    driver.findElement(By.id("solucionDudas")).clear();
    driver.findElement(By.id("solucionDudas")).sendKeys("solucionadas");

    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    //Se verifica que en la lista de respuesta hallan aparecido los cambios en el elemento y tambin el mensaje de edicin exitosa.
    WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));

        if (elems.get(0).getText().equals("opinion1")) {
            fail = true;
        }

    }
    //  driver.findElement(By.linkText("Proyectos")).click();
    /**
     * Comando que realiza click sobre el boton "create" del toolbar. La
     * funcin 'find' encuentra el control y posteriormente hace clic en el
     * mismo. La forma en la que se busca el control es utilizando
     * expresiones xPath ya que los id de los mismos nunca son iguales (se
     * generan con junto con el valor de componentId que vara).
     */
    driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();

    /**
     * Comando que duerme el Thread del test por 2 segundos para dejar que
     * el efecto 'slide down' de backbone abra el formulario de createSport.
     */
    Thread.sleep(2000);

    /**
     * Comando que busca el elemento 'name' en el html actual.
     * Posteriormente limpia su contenido (comando clean).
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("opinion1");
    driver.findElement(By.id("contenido")).clear();
    driver.findElement(By.id("contenido")).sendKeys("contenido1");
    driver.findElement(By.id("calificacion")).clear();
    driver.findElement(By.id("calificacion")).sendKeys("calificacion1");
    driver.findElement(By.id("dificultadEjercicios")).clear();
    driver.findElement(By.id("dificultadEjercicios")).sendKeys("dificultad1");
    driver.findElement(By.id("solucionDudas")).clear();
    driver.findElement(By.id("solucionDudas")).sendKeys("solucionadas");

    Thread.sleep(2000);
    Thread.sleep(2000);
    Thread.sleep(2000);

    List<WebElement> a = driver.findElements(By.xpath("//button[contains(@id,'create')]"));
    a.get(1).click();
    Thread.sleep(2000);
    Thread.sleep(2000);
    // driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();
    List<WebElement> b = driver.findElements(By.id("name"));
    b.get(1).sendKeys("holaa");
    // driver.findElement(By.id("name")).sendKeys("emprendimiento");
    Thread.sleep(2000);

    /**
     * Comando que encuentra y hace clic sobre el boton "Save" del toolbar
     * (una vez mas encontrado por una expresin Xpath)
     */
    List<WebElement> c = driver.findElements(By.xpath("//button[contains(@id,'save')]"));
    c.get(1).click();
    c.get(0).click();

}

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

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

        }

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

}

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

@Test
public void testUpdateRecurso() throws Exception {
    driver.get(baseUrl + "/ClinicaDeProblemas.web/recurso.html");
    //    driver.findElement(By.linkText("Proyectos")).click();
    //Se hace clic en  el vinculo "Edit" del primer elemento de la lista de sports (el elemento que se cre en la anterior prueba)
    driver.findElement(By.linkText("Editar")).click();
    Thread.sleep(2000);//from  www  .  jav  a2s  .  c om
    //Se realiza el mismo proceso de diligenciamento de los campos con los cambios
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("Recurso1");
    driver.findElement(By.id("tema")).clear();
    driver.findElement(By.id("tema")).sendKeys("tema1");
    driver.findElement(By.id("dificultad")).clear();
    driver.findElement(By.id("dificultad")).sendKeys("dificultad1");
    driver.findElement(By.id("tipo")).clear();
    driver.findElement(By.id("tipo")).sendKeys("tipo1");
    driver.findElement(By.id("semestre")).clear();
    driver.findElement(By.id("semestre")).sendKeys("201220");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("fisica1");
    driver.findElement(By.id("Url")).clear();
    driver.findElement(By.id("Url")).sendKeys("http://url");

    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    //Se verifica que en la lista de respuesta hallan aparecido los cambios en el elemento y tambin el mensaje de edicin exitosa.
    WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));

        if (elems.get(0).getText().equals("Recurso1")) {
            fail = true;
        }

    }
    //  driver.findElement(By.linkText("Proyectos")).click();
    /**
     * Comando que realiza click sobre el boton "create" del toolbar. La
     * funcin 'find' encuentra el control y posteriormente hace clic en el
     * mismo. La forma en la que se busca el control es utilizando
     * expresiones xPath ya que los id de los mismos nunca son iguales (se
     * generan con junto con el valor de componentId que vara).
     */
    driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();

    /**
     * Comando que duerme el Thread del test por 2 segundos para dejar que
     * el efecto 'slide down' de backbone abra el formulario de createSport.
     */
    Thread.sleep(2000);

    /**
     * Comando que busca el elemento 'name' en el html actual.
     * Posteriormente limpia su contenido (comando clean).
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("Recurso1");
    driver.findElement(By.id("tema")).clear();
    driver.findElement(By.id("tema")).sendKeys("tema1");
    driver.findElement(By.id("dificultad")).clear();
    driver.findElement(By.id("dificultad")).sendKeys("dificultad1");
    driver.findElement(By.id("tipo")).clear();
    driver.findElement(By.id("tipo")).sendKeys("tipo1");
    driver.findElement(By.id("semestre")).clear();
    driver.findElement(By.id("semestre")).sendKeys("201220");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("fisica1");
    driver.findElement(By.id("Url")).clear();
    driver.findElement(By.id("Url")).sendKeys("http://url");
    Thread.sleep(2000);
    Thread.sleep(2000);
    Thread.sleep(2000);

    List<WebElement> a = driver.findElements(By.xpath("//button[contains(@id,'create')]"));
    a.get(1).click();
    Thread.sleep(2000);
    Thread.sleep(2000);
    // driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();
    List<WebElement> b = driver.findElements(By.id("name"));
    b.get(1).sendKeys("bla");
    // driver.findElement(By.id("name")).sendKeys("emprendimiento");
    Thread.sleep(2000);

    /**
     * Comando que encuentra y hace clic sobre el boton "Save" del toolbar
     * (una vez mas encontrado por una expresin Xpath)
     */
    List<WebElement> c = driver.findElements(By.xpath("//button[contains(@id,'save')]"));
    c.get(1).click();
    c.get(0).click();

}

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

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

        }

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

}

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

@Test
public void testUpdateUTI() throws Exception {
    driver.get(baseUrl + "/ClinicaDeProblemas.web/uTI.html");
    //    driver.findElement(By.linkText("Proyectos")).click();
    //Se hace clic en  el vinculo "Edit" del primer elemento de la lista de sports (el elemento que se cre en la anterior prueba)
    driver.findElement(By.linkText("Editar")).click();
    Thread.sleep(2000);//from  ww  w  .j a  v a  2 s.co  m
    //Se realiza el mismo proceso de diligenciamento de los campos con los cambios
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("taller1");
    driver.findElement(By.id("salon")).clear();
    driver.findElement(By.id("salon")).sendKeys("Salon1");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("materia1");
    driver.findElement(By.id("informacion")).clear();
    driver.findElement(By.id("informacion")).sendKeys("info1");

    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    //Se verifica que en la lista de respuesta hallan aparecido los cambios en el elemento y tambin el mensaje de edicin exitosa.
    WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]"));
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));

        if (elems.get(0).getText().equals("uTI editada")) {
            fail = true;
        }

    }
    //  driver.findElement(By.linkText("Proyectos")).click();
    /**
     * Comando que realiza click sobre el boton "create" del toolbar. La
     * funcin 'find' encuentra el control y posteriormente hace clic en el
     * mismo. La forma en la que se busca el control es utilizando
     * expresiones xPath ya que los id de los mismos nunca son iguales (se
     * generan con junto con el valor de componentId que vara).
     */
    driver.findElement(By.xpath("//button[contains(@id,'create')]")).click();

    /**
     * Comando que duerme el Thread del test por 2 segundos para dejar que
     * el efecto 'slide down' de backbone abra el formulario de createSport.
     */
    Thread.sleep(2000);

    /**
     * Comando que busca el elemento 'name' en el html actual.
     * Posteriormente limpia su contenido (comando clean).
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).clear();
    /**
     * Comando que simula la escritura de un valor en el elemento(sendKeys)
     * con el String de parmetro sobre // el elemento encontrado.
     */
    driver.findElement(By.id("name")).sendKeys("taller1");
    driver.findElement(By.id("salon")).clear();
    driver.findElement(By.id("salon")).sendKeys("Salon1");
    driver.findElement(By.id("materia")).clear();
    driver.findElement(By.id("materia")).sendKeys("materia1");
    driver.findElement(By.id("informacion")).clear();
    driver.findElement(By.id("informacion")).sendKeys("info1");

    Thread.sleep(2000);
    Thread.sleep(2000);
    Thread.sleep(2000);

    driver.findElement(By.xpath("//button[contains(@id,'add')]")).click();
    Thread.sleep(2000);
    Thread.sleep(2000);
    driver.findElement(By.id("selection")).click();
    List<WebElement> a = driver.findElements(By.xpath("//button[contains(@id,'add')]"));
    a.get(1).click();
    a.get(0).click();
    List<WebElement> c = driver.findElements(By.xpath("//button[contains(@id,'save')]"));

    c.get(0).click();

}