Навигация по нумерации страниц с использованием Selenium - PullRequest
0 голосов
/ 07 ноября 2019

https://www.seleniumeasy.com/test/table-pagination-demo.html

Пытаюсь автоматизировать вышеуказанную страницу. Используя Css, когда я получаю все имена с первой страницы, он получает все имена со всех 3 страниц. Этот CSS получает все имена вместо 1-й страницы. By.cssSelector (". Table.table-hover> tbody> tr> td: nth-child (2)");

Я пробовал ниже код

int paginationsize = tablepagination.PaginationForLoop().size();

    System.out.println(paginationsize);

    ArrayList<String> names = new ArrayList<String>();

    for (int i = 2; i < paginationsize; i++) {

        // Get common xpath/css for the page buttons and loop through them one by one
        String paginationSelector = "/html[1]/body[1]/div[2]/div[1]/div[2]/div[1]/ul[1]/li[" + i + "]/a[1]";
        driver.findElement(By.xpath(paginationSelector)).click();

        System.out.println("Selected the page " + i);
        Thread.sleep(2000);

        // Get the names of all the elements for page i
    //  java.util.List<WebElement> namesElements = tablepagination.FirstColumnNumbers();

         java.util.List<WebElement> namesElements = driver.findElements(By.cssSelector(".table.table-hover>tbody>tr>td:nth-child(2)"));

        // loops through all the names and add those name to the defined names list
        for (WebElement namesElements1 : namesElements) {

            names.add(namesElements1.getText());
        }

        //loop through the names and print all the names
        //Issue this is printing all the names from 3 pages. I just need to print 1st page then 2nd and then 3rd.
        for (String testname : names) {
            System.out.println(names);
        }

    }

    int totalNames = names.size();

    //Instead of printing 13 it prints 39 as total names
    System.out.println("Total Number of Names: " + totalNames);

Как я могу получитьтолько 5 имен с первой страницы и затем 5 со второй страницы и 3 с третьей страницы. Из моего селектора CSS он получает все 13 имен со страницы 1 вместо 5 имен. Нужна помощь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...