我的應用程序中,每當一個新情況是在應用程序中添加的表中創建一個新的行。該行有少量列,列的內容可以與其他列的內容相似。我需要找到,如果「文本」是目前排。以下是我的代碼:如何驗證連續文本的存在。 (斷言VS確認)
@Test (priority = 2)
public void SaveStatus()
{
WebElement element = driver.findElement(By.partialLinkText("Case Listing")); //To find 'Case Listing' button on dashboard
Actions action = new Actions (driver);
action.moveToElement(element); //Move mouse and hover to 'Case Listing' button
action.click().build().perform(); //Click on 'Case Listing' button
List<WebElement> newcase = driver.findElements(By.xpath("//*[@id='caseList']/tbody/tr[1]"));//find the new case saved in the caselist
String CaseStatus = ((WebElement) newcase).getText();
if (CaseStatus.contains("Draft")){
Assert.assertTrue(isTextPresent("Draft"));
}
System.out.println("Test Case 3 --> Case Status is draft");
我需要驗證該行中的「草稿」文本的存在。該文本將始終顯示在4列中。其他行也可以有類似的文字,因此我不想使用getPageSource().contains
。這是我得到的錯誤:
java.util.ArrayList cannot be cast to org.openqa.selenium.WebElement
@Sanchit您是否驗證了這一點? – Akarsh
是的。試過這個。現在得到這個錯誤'陳舊元素參考:元素沒有連接到頁面document' – Sanchit
此異常時webelement從DOM破壞會發生。執行調試,在哪一行你得到這個異常。在使用該Web元素之前是否有任何頁面刷新?如果發生,我們需要再次找到元素並對其執行操作。 – Akarsh