我试图在使用 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 显示“页面已过期”。
请指教。