Seleniumを使用してWebページのJUnitテストを作成しており、期待されるテキストがページ内に存在することを確認しようとしています。私がテストしているWebページのコードは次のようになります。
<div id="recipient_div_3" class="label_spacer">
<label class="nodisplay" for="Recipient_nickname"> recipient field: reqd info </label>
<span id="Recipient_nickname_div_2" class="required-field"> *</span>
Recipient:
</div>
期待されるものとページにあるものを比較したいので、Assert.assertTrue()を使用したいと思います。私はdivからすべてを取得するために、私ができることを知っています
String element = driver.findElement(By.cssSelector("div[id='recipient_div_3']")).getText().replaceAll("\n", " ");
ただし、これは「reqd info * Recipient:」を返します。
他のタグなしで、cssSelectorを使用してdiv(「受信者」)からテキストを取得する方法はありますか?