JavaでSeleniumを使用しています.Spanタグからテキストを取得できません。空の文字列を返します。 HTMLコード:テキストが含まれているときにdivからテキストを取得できません<span>
<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>
これは、セレンコードです:
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
空を返します。
@N。 Holは働いている私のコードを試してください – iamsankalp89
ありがとう。このコードは本当に私を助けました!すべて正常に動作します) –