-3
我需要捕獲顯示的錯誤消息,我嘗試了很多方法,但每種方法都拋出異常 - 無法找到元素, 請幫助代碼。這些是我嘗試過的方法。也沒有ID,它是div元素。像這樣的東西...無法捕獲錯誤消息 - 硒java的junit
<div id="webformErrors" class="text" name="errorContent">
<div>
There were 4 errors:
<ul>
<li>
You did not enter a value for:
<b>First Name</b>
</li>
<li>
You did not enter a value for:
<b>Last Name</b>
</li>
<li>
<li>
//String errormsg;
![enter image description here][1]errormsg = Hcd.findElement(By.xpath("//div[@id=webformErrors']/text()")).getText();
// WebElement divElement = Hcd.findElement(By.className("errorContent"));
// Hcd.findElement(By.name("There were 4 errors:")).isDisplayed();
**String pstring = Hcd.findElement(By.id("webformErrors")).getText();
System.out.println(pstring);
此問題需要校對。請檢查它並修正格式和結構。 – jbaums