2012-08-09 128 views
2

我試圖使用後webdriver的硒(硒的dotnet-2.25.1)+ IEDriverServer.exe數據重新發布傳遞模式警報窗口後的數據再處理後的模態警告窗口(IEDriverServer_Win32_2.25.2)。不能(使用硒的webdriver C#和IE)

這是我測試的C#代碼:

static void Main(string[] args) 
    { 
     IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(); 

     // Navigating to gmail.com and submitting wrong data 
     driver.Navigate().GoToUrl("gmail.com"); 
     driver.FindElement(By.Id("Email")).SendKeys("testuser"); 
     driver.FindElement(By.Id("signIn")).Click(); 
     Thread.Sleep(8000); 

     // making the data re-post by F5 
     driver.Navigate().Refresh(); 

     // Handling the aller and accepting it 
     IAlert alert = driver.SwitchTo().Alert(); 
     Console.WriteLine(alert.Text); 
     alert.Accept(); 
    } 

這是程序的輸出:

Started InternetExplorerDriver server (32-bit) 
    2.25.2.0 
    Listening on port 2783 
    To display the webpage again, Internet Explorer needs to 
    resend the information you've previously submitted. 

    If you were making a purchase, you should click Cancel to 
    avoid a duplicate transaction. Otherwise, click Retry to display 
    the webpage again. 
    Press any key to continue . . .     

至於結果,警報窗口會消失,沒有任何數據重新發布和IE顯示「頁面已過期」。

請指教。

+0

問題可能在於這樣一個事實,而不是「確定」和「取消」按鈕顯示的警報,它的「重試」和「取消」。您可以通過使用alert.SendKeys來解決這個問題()和發送任何一個「ALT + R」或「空格鍵」命令。 – 2012-08-09 18:07:25

回答

0

的「警報」中硒的webdriver定義爲一兩件事,只有一兩件事:把通過JavaScript來顯示一個對話框。即,警報API只能可靠地用於由JavaScript alert()confirm(),或prompt()功能創建的對話。對於任何其他對話框,您可能會很幸運,但該API不適用於這些對話框。