HTMLポップアップには2つのボタンがほとんど似ています。両方のボタンは、スパンテキストを除いて同じですが、何も違いはありません。セレンのwebdriverに複数のクラスを持つボタンのxpathを定義する方法
誰でもお勧めします、OKボタンのxpathを書く方法はありますか?
私は以下のxpathを書きましたが、システムにエラーが表示されました。
私のXpath
driver.findElement(By.xpath("//div[@class='ui-dialog-buttonset']/descendant::button[@class='ui-button']/span[contains(@class, 'ui-button-text') and text() = 'OK']")).click();
エラーここ
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
は、ポップアップの私のHTMLコードです:
HTML
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons ui-draggable" style="height: auto; width: 350px; top: 295.5px; left: 621px; display: block; z-index: 102;" tabindex="-1" role="dialog" aria-describedby="DivExtension" aria-labelledby="ui-id-2">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix ui-draggable-handle">
<span id="ui-id-2" class="ui-dialog-title">内線番号</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" type="button" role="button" title="Close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">Close</span>
</button>
</div>
<div id="DivExtension" class="display-none ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 0px; max-height: none; height: 68px;">
<div id="extRow" class="display-none" style="display: block;">
<p class="form-label">
<label for="extension">内線番号</label>
</p>
<p class="form-input">
<input id="Extension" class="text" type="text" placeholder="Extension" value="">
</p>
</div>
</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" style="height: 34px; width: 104px;" role="button">
<span class="ui-button-text">OK</span>
</button>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" style="height: 34px; width: 124px;" role="button">
<span class="ui-button-text">キヤンセル</span>
</button>
</div>
</div>
lauda..Thank @あなたは非常に多く、第三の選択肢は私のために動作します。 // button [@ class = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only] [。 )、 'OK')]] – Swa
ニース。 //ボタン[contains(@class、 'ui-button')] [.// span [contains(text()、 'OK')]] – lauda
ちょうど好奇心、何が間違っている私のxpathで?すべてのボタンクラスを定義する必要はありますか? – Swa