2016-07-06 6 views
0

JavaでSelenium Web Driverを使用してモデルダイアログボックス(Bootstrapで開発)にアクセスしようとしています。ここで私はタイトル、コンテンツ、ボタンにアクセスできます。Selenium Web DriverとJavaを使用してブートストラップで開発されたモデルダイアログボックスのコンテンツへのアクセス方法

もう1つの点はここです。xPathは動的に生成されるたびに、xPathの生成方法が異なります。私は部分的にxPathにマッチさせることで解決できることを知っています。

この問題を解決するのに役立ちます。ここで私のモデルボックスデザインのイメージを付けています。

enter image description here

ここでここでのコードスニペット

enter image description here

コード

<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <div class="bootstrap-dialog-header"> 
       <div class="bootstrap-dialog-close-button" style="display: none;"> 
        <button class="close"> 
        × 
        </button> 
       </div> 
       <div class="bootstrap-dialog-title" id="5f663313-d82d-4ab8-9712-6665e80a3654_title"> 
       Member Registration 
       </div> 
      </div> 
     </div> 
     <div class="modal-body"> 
      <div class="bootstrap-dialog-body"> 
       <div class="bootstrap-dialog-message"> 
        Sample Message Sample Message Sample Message Sample Message Sample Message Sample Message. 
       </div> 
      </div> 
     </div> 
     <div class="modal-footer"> 
      <div class="bootstrap-dialog-footer"> 
       <div class="bootstrap-dialog-footer-buttons"> 
        <button class="btn btn-primary" id="353ab962-44d3-497f-8318-6db703b460d8"> 
         Ok 
        </button> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
+1

ブートストラップバージョンとは何ですか?ブートストラップコンポーネント名は何ですか?アプリケーションのリンクやサンプルのHTMLコードを提供してください。これまでに何を試しましたか? – Madhan

+0

コード@Madhanの添付ファイルにチェックをしてください – Nikunj

+0

@Nikunj解決策が本当に必要な場合は、スクリーンショットとセレンコードの代わりにHTMLコードを入力する必要があります。 –

答えて

1
//div[@class="bootstrap-dialog-title"] for Title 

//div[@class="bootstrap-dialog-message"] for message 

//div[@class="bootstrap-dialog-footer-buttons"]/button for buttton 
+0

このソリューションは私にモデルの3つの要素すべてにアクセスできます。 ここには私のために働くコードがあります: driver.findElement(By.xpath( "// div [@ class = 'bootstrap-dialog-title']"))。getText(); \t driver.findElement(By.xpath( "// div [@ class = 'ブートストラップダイアログメッセージ']))。getText(); \t driver.findElement(By.xpath( "// div ="ブートストラップダイアログフッタボタン "/ボタン"))。 – Nikunj

+0

@Nikunjは単に 'By.className'を使って得ることができるなら' xPath'を使うのを避けます... 'xPath'を使うよりも速くなります... –

0
driver.switchTo().activeElement(); 
Thread.sleep(5000); 
driver.findElement(By.xpath("//button[contains(text(),'"+data+"')]")).click(); 

これは私の問題を解決し、 です私はまた、メッセージにアクセスすることを望んでいるが、私はできないccess

+0

私は、ベストプラクティスのために、 'Thread.sleep'の代わりに' WebDriverWait'を実装することをお勧めします... –

関連する問題