【发布时间】:2014-10-29 09:12:30
【问题描述】:
String a=driver.findElement(By.id(locator))).getAttribute("value");
System.out.println("the value is "+ a);
Log.info(" Required object is present in the applicaiton"+ object);
<p locale="" isnumeric="false" basetype="String" class="outputText twControl twOutputText" id="InputText12">**MANTPLAP29102014100955627**</p>
我需要从上面的 HTML 代码中获取 MANTPLAP29102014100955627 值。
请帮忙..
【问题讨论】:
-
在你的情况下,你只需要
getText()的元素。只有在需要获取内联属性时才需要使用.getAttribute(),例如getAttribute("basetype") -
当我使用 basetype.. 它返回字符串。
-
这是正确的,因为你的元素的内联属性是
basetype="String"。因此,要获取元素的 TEXT,请使用getText()。它是文本,因为它不是内联属性,并且位于<p>和</p>标记之间。