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

时间:2014-02-06 01:43:13

标签: java html text selenium message

我需要捕获显示的错误消息,我尝试了很多方法,但每个方法抛出异常 - 无法找到元素, 请帮助代码。这些是我试过的方法。也没有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);

1 个答案:

答案 0 :(得分:0)

您给出了类名和错误名称。 classname是&#34; text&#34;和名称是&#34; errorContent&#34;。

WebElement divElement = Hcd.findElement(By.className("text"));