簡體   English   中英

沒有警報/沒有找到模態對話框 - WebDriver無法捕獲JS錯誤

[英]No Alert is present/No modal dialog found — WebDriver unable to catch JS error

我正在為我們的生產站點自動化“添加員工”基於表單的測試。 當輸入id,或已存在的電子郵件或名稱時,會彈出一個服務錯誤,表明該員工無法注冊。 即使這個框出現了,測試通過:(。我嘗試在我的代碼中使用driver.switchTo()。alert()函數。這就是發生的事情:

Alert alert=driver.switchTo().alert();
String text=alert.getText();
System.out.println(text);

使用Firefox 7 + Selenium WebDriver 2.8.0:

org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information); duration or timeout: 2.11 seconds
    Build info: version: '2.8.0', revision: '14056', time: '2011-10-06 12:41:48'
    System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.37.6-0.7-desktop', java.version: '1.6.0_26'
    Driver info: driver.version: RemoteWebDriver

使用Chrome +網絡驅動程序:

[1011/131949:ERROR:automation_json_requests.cc(59)] JSON request failed: GetAppModalDialogMessage
    with error: No modal dialog is showing

錯誤快照: 當員工已經存在時

題:

如果我沒有得到對話框的文本,那很好。 這是唯一會出現的警報。 所以,只要知道警報已經出現就可以解決我的問題。 但是,這兩件事都說不存在警報/模態對話:(

謝謝。

編輯:我也試過這個:

Selenium selenium=new WebDriverBackedSelenium(driver,baseUrl);
System.out.println(selenium.isAlertPresent());

這給出了錯誤。 這不是警報箱嗎? 它不是模態對話嗎? 如果它不是那些東西,我怎么在頁面上找到它的存在?

很多時候發生的事情是Selenium代碼在瀏覽器呈現警報之前執行。 我傾向於做的是這樣的事情:

Alert getAlert() {
    try {
        Alert alert = driver.switchTo().alert();
        return alert;
    } catch (NoAlertPresentException e) {
        // no alert to dismiss, so return null
        return null;
    }
}

我真的不認為這是理想的,但我現在還不知道Selenium有更好的方法。 我傾向於定期從我的測試中盲目地調用它,如果它返回警報,我會解雇它。 如果您希望來自應用程序的警報並希望在繼續之前將其解除,請將其包裝在while循環中。

我也遇到了與模型對話框相同的問題。

你要做的是找到ok buttion的xpath並繼續。

我也做了同樣的事並成功完成了它。

找到webelement並在webelement和點擊'ok'按鈕之間等待。

不要使用像driver.switchto.alert.accept();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM