[英]Selenium - Java - Unable to capture the Error popup that appears once in 12 times of test execution
[英]Unable to capture error message - selenium java junit
我需要捕獲顯示的錯誤消息,我嘗試了很多方法,但每種方法都會拋出異常 --unable to find element,請幫助提供代碼。 這些是我試過的方法。另外,沒有ID,它是div元素。 像這樣的東西......
<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);
你給的類名和名稱是錯誤的。 類名是“text”,名稱是“errorContent”。
WebElement divElement = Hcd.findElement(By.className("text"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.