[英]Unable to click on a button in Pop-up in Selenium webdriver using java
我試圖在Selenium的彈出窗口中單擊“是”按鈕,但無法這樣做。 HTML代碼是:
<div id="dialoguebuttons">
<div style="left: 60px; color: rgb(0, 102, 153); padding-top: 5px; font-size: 16px; font-weight: bold; float: left; position: relative;" id="dialog_question">Activate Riskfirst Rapid?</div>
<a id="dialogYesButton" class="button btn-orng" tabIndex="101" href="#">
<span class="btn-inner">Yes</span>
</a>
<a id="dialogNoButton" class="button btn-orng" tabIndex="102" href="#">
<span class="btn-inner">No</span>
</a>
</div>
</div>
我嘗試執行的Java代碼:
driver.findElement(By.xpath(//*[@id="save_quote_button"]/span)).click(); // After this the pop-up window gets displayed
driver.findElement(By.xpath(//*[@id="dialogYesButton"]/span)).click(); // Trying to click on the Yes button on the pop-up
它只是跳過該步驟而沒有實際給出任何錯誤。
當您嘗試單擊“是”按鈕時,此xpath可能會幫助您:
driver.findElement(By.xpath(//*[@id="dialoguebuttons"]/a[text()='Yes')).click();
讓我知道這是否對您有幫助。
如果您使用的是firefox瀏覽器,則安裝firebug
Addon和firepath
Addon,並使用firepath檢查該元素,並在此代碼中粘貼以下代碼中雙引號之間的xpath:
driver.findElement(By.xpath(" ")).click();
如果您不熟悉firebug
請參考此鏈接並嘗試。 它將幫助您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.