【发布时间】:2014-03-02 18:41:18
【问题描述】:
我需要捕获显示的错误消息,我尝试了很多方法,但每个方法都会抛出异常——无法找到元素, 请帮助代码。这些是我尝试过的方法。另外,没有 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);
【问题讨论】:
-
这个问题需要校对。请检查并修正格式和结构。
标签: java html text selenium message