2017-12-22 127 views
-1

私はSeleniumとjavaを使用していますので、モーダル内の要素をクリックすることはできません。 シナリオは フレーム内のアイテムをクリックした後、モーダルを開き、このモーダル内の要素をクリックする必要がありますが、それを得ることはできません。Selenium - モーダル内の要素をクリックできません

<div class="modal-dialog"> 

    <div class="modal-content modal-custom-content"> 
     <div class="modal-header"> 
      ... 
     </div> 
     <div class="modal-body"> 
      <form id="formTo" class="form-container"> 
       <div class="row"> 
        ... 
       </div> 
       <div class="small-space"></div> 
       <input ...> 
       <div class="row"> 
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> 
         ... 
        </div> 
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> 
         ... 
        </div> 
       </div> 
       <div class="row"> 
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> 
         ... 
        </div> 
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> 
         ... 
        </div> 
       </div> 
       <div class="small-space"></div> 
       <div class="row"> 
        ... 
       </div> 
      </form> 
     </div> 
     <div class="small-space"></div> 
     <div class="modal-footer"> 
      <div class="row text-center"> 
       <div class="col-md-6 col-sm-6 col-xs-12"> 
        <button class="btn modal-button full-btn" id="saveexit" type="button">SAVE AND EXIT</button> 
       </div> 
       <div class="col-md-6 col-sm-6 col-xs-12"> 
        ... 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

が、これは次のとおりです。ここで

while (itr.hasNext()) { 
    String popup = itr.next(); 
    System.out.println("itr: " + popup); 
    driver.switchTo().window(popup); 
} 

は私のモーダルのhtmlです:私もswitchTo()この方法で試してみました

js.executeScript("document.getElementById('saveexit').scrollIntoView(true);"); 

は、私はすでにしてみましたfirefox devツールから取得したCSSパス:

html.no-touch body div.remodal-wrapper.remodal-is-opened div.modaliAdesione.remodal.remodal-is-initialized.remodal-is‌​-opened div.modal-dialog div.modal-content.modal-custom-content div.modal-footer div.row.text-center div.col-md-6.col-sm-6.col-xs-12 button#saveexit.btn.modal-button.full-btn 

オブジェクトが見つかりません。

  • 質問1:要素がモーダル内にある場合は、 の別の方法で管理する必要がありますか?
  • 質問2:最終的にボタンをクリックする方法 saveexitが機能しますか?ここ

HTMLのコードスニペットを共有している:ここではhttps://codeshare.io/arLW9q

は、Javaコードです:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"saveexit\"]"))) 

私もして試してみました:

cssSelector: #saveexit 
cssPath: html.no-touch body div.remodal-wrapper.remodal-is-opened div.modaliAdesione.remodal.remodal-is-initialized.remodal-is-opened 
div.modal-dialog div.modal-content.modal-custom-content div.modal-footer div.row.text-center div.col-md-6.col-sm-6.col-xs-12 
button#saveexit.btn.modal-button.full-btn 
xpath: //*[@id="saveexit"] 

注意してください。ブラウザのコンソールからdocument.getElementById('saveexit').click();を実行すると、それは動作します

+1

モーダルに切り替えることができるウィンドウではありません。それはページのHTMLだけです。どのJavaコードを試してみましたか?結果は何ですか?エラーメッセージなど – JeffC

+0

私が試したJavaコードはjs.executeScriptです。結果はsaveexitが存在しないというエラーです。 – eeadev

答えて

0

は、私はそれが私のスクリプト内部のjQueryを使用して固定しました。ここ

は回線符号である:

js.executeScript("$('#saveexit').trigger('click');");

私はそれが将来的に誰かを助けることができると思います。

私は無地のJavaScriptが働いていなかった理由を知らない

...

1

ベストプラクティスに従ってSelenium-Javaクライアントを使用しているので、最も効率的で実績のあるclick()メソッドを呼び出す必要があります。 click()メソッドから生じるエラーに応じて、他の代替ソリューションでも作業できます。

私はJavascriptExecutorswitchTo().window()を使用して、コードの試験から見ることができるように、あなたはよくSAVE AND EXITボタンを表すWebElementを識別やりなさい。

では、次のコードブロックを使用することができますSAVE AND EXITボタンをクリックしてください:

new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='modal-dialog']//div[@class='modal-footer']//button[@class='btn modal-button full-btn' and @id='saveexit']"))).click(); 
+0

Debさん、ありがとうございます。できるだけ早く試してみてください。 – eeadev

+0

動作しません。この "期待された条件が失敗しました:By.xpathによって見つけられる要素の可視性を待っています:..." – eeadev

+0

もう少し "outerHTML"を見せてください。可能な要素は 'iframe'内にあり、' xpath'は一意ではありません。 – DebanjanB

関連する問題