我正在嘗試使用Selenium (java)單擊警報彈出消息上的Yes/No按鈕。我知道我們有 accept() 函數(shù)來單擊任何警報的Ok按鈕,但這在這種情況下不起作用。我嘗試了以下代碼:Alert alert = driver.switchTo().alert();alert.accept();這是警報消息的 HTML 代碼:<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"> <div class="ui-dialog-buttonset"> <button type="button" class="ui-button ui-widget ui-state-default ui-corner- all ui-button-text-only" role="button" aria-disabled="false"> <span class="ui-button-text">Yes</span> </button> <button type="button" class="ui-button ui-widget ui-state-default ui-corner- all ui-button-text-only" role="button" aria-disabled="false"> <span class="ui-button-text">No</span> </button></div></div>請幫忙!
3 回答

胡子哥哥
TA貢獻(xiàn)1825條經(jīng)驗 獲得超6個贊
您只需單擊“是” 按鈕即可。(無需切換到警報):
代碼 :
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Yes']/parent::button"))).click();

撒科打諢
TA貢獻(xiàn)1934條經(jīng)驗 獲得超2個贊
不是Javascript alert
。
使用此 xpath 單擊該按鈕
"//span[normalize-space()='Yes']/.."
添加回答
舉報
0/150
提交
取消