[Selenium Java] Bài 24: Kiểm tra giá trị khi tìm kiếm trong table

Cách xử lý so sánh dữ liệu khi tìm kiếm hoặc lọc trong table

Hàm xử lý cho ProjectPage.class


public void checkSearchTableByColumn(int column, String value) {
        //Xác định số dòng của table sau khi search
        List<WebElement> row = driver.findElements(By.xpath("//table//tbody/tr"));
        int rowTotal = row.size(); //Lấy ra số dòng
        System.out.println("Số dòng tìm thấy: " + rowTotal);
        //Duyệt từng dòng
        for (int i = 1; i <= rowTotal; i++) {
            WebElement elementCheck = driver.findElement(By.xpath("//table//tbody/tr[" + i + "]/td[" + column + "]"));

            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("arguments[0].scrollIntoView(true);", elementCheck);

            System.out.print(value + " - ");
            System.out.println(elementCheck.getText());
            Assert.assertTrue(elementCheck.getText().toUpperCase().contains(value.toUpperCase()), "Dòng số " + i + " không chứa giá trị tìm kiếm.");
        }

    }​

 

Gọi lại bên test case

@Test
    public void searchProject() throws InterruptedException {
        projectPage.enterSearchValue("4,000");
        Thread.sleep(2000);
        projectPage.checkSearchTableByColumn(4, "4,000");
    }
  • Anh Tester

    Đường dẫu khó chân vẫn cần bước đi
    Đời dẫu khổ tâm vẫn cần nghĩ thấu

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: new

Filename: post/post_detail.php

Line Number: 385

Backtrace:

File: /home/anhteste/public_html/application/views/frontend/post/post_detail.php
Line: 385
Function: _error_handler

File: /home/anhteste/public_html/application/views/frontend/layout/layout_view.php
Line: 297
Function: view

File: /home/anhteste/public_html/application/core/MY_Controller.php
Line: 34
Function: view

File: /home/anhteste/public_html/application/controllers/frontend/Post.php
Line: 59
Function: render

File: /home/anhteste/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Trying to get property 'slug' of non-object

Filename: post/post_detail.php

Line Number: 385

Backtrace:

File: /home/anhteste/public_html/application/views/frontend/post/post_detail.php
Line: 385
Function: _error_handler

File: /home/anhteste/public_html/application/views/frontend/layout/layout_view.php
Line: 297
Function: view

File: /home/anhteste/public_html/application/core/MY_Controller.php
Line: 34
Function: view

File: /home/anhteste/public_html/application/controllers/frontend/Post.php
Line: 59
Function: render

File: /home/anhteste/public_html/index.php
Line: 315
Function: require_once

https://anhtester.com//blog/selenium-java/" data-width="100%" data-numposts="4">