2016-07-06 12 views
0

我想用Java中的Selenium Web驅動程序訪問模型對話框(在Bootstrap中開發),我無法這樣做。在這裏,我要訪問標題,內容和按鈕。如何訪問使用Selenium Web驅動程序和Java在Bootstrap中開發的模型對話框內容

還有一點是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

什麼是bootstrap版本?什麼是引導組件名稱?提供應用程序鏈接或示例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(); ();}}。getText();}}。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 ();}}。點擊();點擊按鈕。 – Nikunj

+0

@Nikunj避免使用'xPath',如果你可以簡單地使用'By.className' ...它會比使用'xPath'更快... –

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

這解決我的問題, 我也想,但我訪問留言無法一個ccess

+0

我建議你最好的實踐,你應該實現'WebDriverWait'而不是'Thread.sleep' ... –

相關問題