在此HTML代码中,我需要使用硒testng获取“状态”文本。
<div class="dojoxGridSortNode">Status</div>
我用的代码是
public static String gettext(){
String Value = null;
try{
Value = webElement.getAttribute("text");
APP_LOGS.debug("Get Text on"+locatorDescription);
}
使用此代码,我无法从html代码获取文本。是否还有其他选择可从html属性获取文本?我也使用了.getText()方法。
提前致谢
您需要将WebElement作为参数传递,以正确使用您的方法。
该webelement可以是以下内容(按照HTML片段,您已添加):
WebElement element = driver.findElement(By.xpath("//div[@class='dojoxGridSortNode']"));
并且,您的方法可以修改为:
public static String gettext(WebElement webElement){
String Value = null;
try{
Value = webElement.getText();
APP_LOGS.debug("Got Text: "+Value);
return Value;
}catch(Throwable e){
//Catch body
}
}
您可以将有关的WebElement作为参数传递给上述方法,然后调用该方法以获取所需的文本
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句