1

現在、Selenium WebDriver でダイアログをテストしようとしていますが、[従業員の作成] ボタンには ID も名前もありません。これがコードの外観です。

<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
    <div class="ui-dialog-buttonset">

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Create Employee</span>
         </button>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Cancel</span>
         </button>

    </div>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Create Employee</span>
         </button>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Cancel</span>
         </button>

</div>

ダイアログボックスのボタンをクリックするJavaコードを誰かに教えてもらえますか? ありがとう

4

4 に答える 4

4

以下のコードを試してください。

 driver.findelement(By.xpath("//button[@type='button']/span[text()='Create Employee']")).click();
于 2013-05-14T07:27:49.647 に答える
1

初心者には面倒だと思った xpath の代わりに、jQueryUI ダイアログで結果に ID を追加できることがわかりました。

それ以外の:

$("#stuff").dialog({
    buttons: {
            "Yes": function() {

書きます:

$("#stuff").dialog({
    buttons: {
            "Yes": { text: "Yes",
                     id: "#mystuff-yes",
                     click: function() {
于 2013-12-20T19:05:24.623 に答える
0

要素を選択する方法がない場合は、 を使用することをお勧めします。操作したい要素をxpath 取得するために、ブラウザにアドオンまたは拡張機能をインストールすることをお勧めします。xpath次に、そのxpathを目的に使用します。

于 2013-05-14T07:22:42.970 に答える