2013-09-23 106 views
1

即時通訊從Chrome瀏覽器處理ALert彈出窗口時遇到問題,我不斷收到以下錯誤消息。 org.openqa.selenium.UnhandledAlertException:意外的警報打開 (會話信息:chrome = 29.0.1547.66) (驅動程序信息:chromedriver = 2.3,平臺= Windows NT 5.1 SP3 x86)。在Chrome驅動程序(Webdriver)上處理警報窗口

這是我到目前爲止嘗試過的。當我到達顯示錯誤的頁面時:

driver.switchTo().alert.accept(); 

也試過。

Alert alert = driver.switchTo().alert(); 
alert.accept(); 

也是同樣的錯誤。

如果有任何解決方案,這將不勝感激。

回答

1

它可能是您的ChromeDriver版本。我不建議總是更新到最新版本的東西。缺陷比比皆是。

我使用ChromeDriver win32_2.0,它工作正常。 Try that version.

+0

感謝您的即時通訊,謝謝您的回覆。 – elcharrua

1

實際上,如果您沒有正確處理警報,則會出現(UnhandledAlertException)。否則,如果您在關閉警報之前對驅動程序實例執行任何操作。

第1步:點擊按鈕//這將導致收到提醒

步驟2://這裏需要提醒處理

在步驟2中,而不是處理警報如果你使用驅動程序實例進行任何其他操作,它將引發UnhandledAlertException異常。

+0

如果無法使用驅動程序實例,我該如何使用它?因爲我不能使用驅動程序isntance創建一個警報實例。這是我處理警報的方法 \t public static boolean manejarAlertas(){ \t \t boolean alerta = true; \t \t嘗試{ \t \t \t \t \t \t // ESPERO 10 Segundo的科莫馬克西莫一闕aparezca EL mensaje德警報。 WebDriverWait等待=新的WebDriverWait(driver,20); \t \t \t等待。直到(ExpectedConditions.alertIsPresent()); (); alert()。accept(); \t \t \t //你好,請點擊確定。 \t \t \t //alert.accept(); \t \t} catch(Exception e){ \t \t \t alerta = false; \t \t} \t \t return alerta; \t} – elcharrua

+0

而不是WebDriverWait只是嘗試靜態等待。我的意思是把一些Thread.sleep(3000);並嘗試相同的。如果它在工作意味着我們可以考慮等待邏輯。 – Santoshsarma

+0

試過這樣做,問題依然存在,我甚至試圖使用ActionKey並按Key.Esc和它的同樣的錯誤。 – elcharrua

0

我得到了這個問題與IE瀏覽器。但是,有兩個簡單的變化就開始下FF喜歡的工作:
1)作爲建議https://stackoverflow.com/a/20611297/2872258同時創造IEDriver我設置的另一種選擇 - 在unexpectedAlertBehaviour =忽略
2)我也WebDriverWait了警報,以設置ImplicityWait爲「0」最開始 - 根據@Santoshsarma說這是另一個問題。

也可能是Chrome的解決方案。

0

我試圖捕捉到stackoverflow錯誤,它爲我工作的解決方法。

try 
{ 
    driver.findElement(By.xpath('xpath')).click(); // command that will trigger the alert window 
} 
catch (StackOverflowError e) 
{ 
    driver.switchTo().alert().dismiss(); // or driver.switchTo().alert().accept(); 
    // the rest of the scripts can be added here 
} 
相關問題