繁体   English   中英

我试图使用页面对象硒从jsp上的表中提取文本

[英]i am trying to pull text from a table on a jsp using page object selenium

所以我正在使用硒页面对象,我已经找到了正确的行并为其指定了ID,但它在控制台中始终为我提供了一个空指针,但是我不知道什么返回了null。

这是页面

    @FindBy(id = "status")
private WebElement confirmedEmergencySignIn;

@FindBy(className = "navbar-brand")
private WebElement dashboardLink;

public EmergenciesInListPage(WebDriver driver) {
    super(driver, PageTitle.EMERGENCYINLIST, PagePath.EMERGENCYOUTLIST);

    // COMPULSORY
    this.driver = driver;
    PageFactory.initElements(driver, this);
}

public Boolean checkEmergencySinedIn(String textToCheck) {
    return confirmedEmergencySignIn.getText().equals(textToCheck);
}

这是硒测试,

    @Test
public void testToShowAllUsersThatAreSignedinOnTheEmergencyList() {
    quickSignIn();
    emergencyPage = dashboardPage.clickEmergencyListLink();
    emergencyPage.clickInOutDropdown();
    emergencyPage.clickSetStatusInLink();
    assertTrue(emergenciesInListPage.checkEmergencySinedIn(STATUS_IN));
    assertTrue(isOnThisPage(PagePath.EMERGENCYINLIST));
}

这是包含表的Jsp部分。 存在数据时,表格将自行填充,

<div class = "containter"> <div class = "table"> <table class="table table-striped"> <tbody> <th> First Name </th> <th> Last Name </th> <th> Status </th> <c:forEach items="${allPeople}" var="P"> <tr> <td>${P.user.forenames}</td> <td>${P.user.surname}</td> <td id="status">${P.status}</td> </tr> </c:forEach> </tbody> </table>
</div> </div>

原因是因为您要遍历${allPeople} ,所以该属性有1个以上的'status' ${allPeople}

@FindBy(id = "status") private WebElement confirmedEmergencySignIn;

不是集合。 您需要将其设为集合或使ID唯一。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM