0
package LoginPagePLot;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SearchRecord {
    public WebDriver driver;

    public SearchRecord(WebDriver driver1) {
        this.driver = driver1;
        WebDriverWait wait = new WebDriverWait(driver, 30);    
    }

    public void clickonuser() {
        WebElement tbody = driver.findElement(By.tagName("tbody"));
        // Now get all the TR elements from the table 
        List<WebElement> allRows = tbody.findElements(By.cssSelector("tbody>tr")); 
        System.out.println(allRows.size());

        // And iterate over them, getting the cells 
        for (WebElement row : allRows) { 
            List<WebElement> cells = row.findElements(By.tagName("td")); 

            // Print the contents of each cell
            for (WebElement cell : cells) { 
                System.out.println(cell.getText());
            }
        }
    }       
}

テスト ケース クラス

package LoginTestCasePlot;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import LoginPagePLot.AddIndividual;
import LoginPagePLot.SearchRecord;


public class VerifySearchRecord {
    public WebDriver driver;
    VerifyloginPF verifylogin=new VerifyloginPF();
    VerifyHomepage verifyhome= new VerifyHomepage();
    VerifyAddIndividual verifyadd=new VerifyAddIndividual();

    @BeforeTest
    public void verifydatainputed() {
        System.out.println("Record added");
        verifyadd.verifydashboardisplayed();
        driver=verifyadd.Adduserdata123();
        System.out.println("Record added in list");
    }
    @Test
    public void viewindividual() {
        SearchRecord srch=PageFactory.initElements(driver, SearchRecord.class);
        srch.clickonuser();
    }    
}

HTML:

<table id="myTable" class="table table-striped dataTable no-footer" role="grid" aria-describedby="myTable_info" style="width: 1061px;">
        <thead>
            <tr role="row"><th class="single-line sorting_asc" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 58px;" aria-sort="ascending" aria-label="
                    Family ID
                : activate to sort column descending">
                    Family ID
                </th><th class="single-line sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 104px;" aria-label="
                    Person Name
                : activate to sort column ascending">
                    Person Name
                </th><th class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 94px;" aria-label="
                    CNIC
                : activate to sort column ascending">
                    CNIC
                </th><th class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 121px;" aria-label="Registered At: activate to sort column ascending">Registered At</th><th class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 35px;" aria-label="City: activate to sort column ascending">City</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 57px;" aria-label="
                    Personas
                ">
                    Personas
                </th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 97px;" aria-label="Qualifications">Qualifications</th><th class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 40px;" aria-label="Status: activate to sort column ascending">Status</th><th class="text-center sorting_disabled" rowspan="1" colspan="1" style="width: 59px;" aria-label="Action(s)">Action(s)</th></tr>
        </thead>

000010 abbas18720-9298862-8

2019/1/22 イスランバッド 000010 abbas18720-9198862-8

1/22/2019イスラムバッド 000010 abbas18721-9212843-8

1/22/2019イスランバッド 000010 abbas18721-9223130-8

2019/1/22 イスランバッド 000010 abbas18721-9223140-8

2019/1/22 イスランバッド 000010 abbas18721-9298862-8

1/22/2019イスラムバッド 000010 abbas18721-9223110-8

2019/1/22 イスランバッド 000010 abbas18721-9223813-8

1/22/2019イスラムバッド 000010 abbas18721-9298843-8

1/22/2019イスラムバッド 000010 abbas18721-9223810-8

2019/1/22イスランバッド

テーブルに 10 行を超える行があるにもかかわらず、常に行サイズ = 0 を返しますが、行サイズを取得できないため、テストを実行できません。xpath、cssセレクター、およびタグ名で試しましたが、row.size();を出力すると行の結果に何も返されません。

この問題を解決するのを手伝ってください。

4

1 に答える 1