2

Selenium WebDriver (selenium-dotnet-2.25.1) + IEDriverServer.exe (IEDriverServer_Win32_2.25.2) を使用してデータを再投稿した後、モーダル アラート ウィンドウを渡そうとしています。

これは私のテスト 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 は「ページの有効期限が切れています」と表示します。

ご意見をお聞かせください。

4

1 に答える 1

0

「アラート」は、Selenium WebDriverで1つ、そして1つだけとして定義されています。JavaScriptを介して表示されるダイアログボックスです。つまり、Alert APIは、JavaScript、、、または関数によって作成されたダイアログにのみ確実に使用alert()できconfirm()ますprompt()。他のダイアログの場合、幸運になるかもしれませんが、APIはそれらのダイアログで機能するようには設計されていません。

于 2012-08-09T19:10:59.967 に答える