【发布时间】:2018-01-15 19:12:56
【问题描述】:
我在 Java 中使用 Selenium。我无法从 span 标签中获取文本,每次都返回一个空字符串。 HTML 代码:
<div class="fade-repeat-animation alert ng-isolate-scope alert-error" ng-class="type && "alert-" + type" ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">
<button class="close" ng-click="close()" type="button" ng-show="closeable">×</button>
<div ng-transclude="">
<span class="ng-scope ng-binding">This text</span>
</div>
</div>
这是 Selenium 代码:
String ipError = within(secs(10)).div(By.xpath("//div[@class='fade-repeat-animation alert ng-isolate-scope alert-error']/div/span")).getAttribute("innerHTML");
我也尝试使用getText() 和getAttribute("textContent"),但总是返回空String。
【问题讨论】: