2017-05-03 104 views
0

我想單擊Selenium彈出窗口上的Yes按鈕,但無法這樣做。 HTML代碼是:無法在使用java的Selenium webdriver彈出按鈕中單擊按鈕

<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 

它只是跳過而不實際給予任何錯誤的一步。

+1

如果你刪除了''/''[@ id =「dialogYesButton」]/span'中的'/ span'會發生什麼? –

+0

你可以點擊SPAN並獲得相同的效果,但是如kiran所說,我會刪除量程,只需點擊ID所指示的A標籤即可。我會走得更遠,並說在這種簡單的情況下不要使用XPath。這應該工作:'driver.findElement(By.id(「dialogYesButton」))。click();' – JeffC

回答

0

當你試圖點擊Yes按鈕,此XPath可以幫助你:

driver.findElement(By.xpath(//*[@id="dialoguebuttons"]/a[text()='Yes')).click();

讓我知道如果這能幫助你。

+0

@MeghaGupta我的答案解決了你的問題嗎? – DebanjanB

0

如果您使用的是Firefox瀏覽器則安裝firebug附加組件和firepath附加組件,並使用firepath檢查該元素在這裏粘貼在下面的代碼中提到雙引號之間的XPath的:

driver.findElement(By.xpath(" ")).click(); 

如果你不熟悉firebug請參考this鏈接並嘗試。它會幫助你。

相關問題