繁体   English   中英

无法捕获错误消息 - selenium java junit

[英]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.

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