2014-11-05 100 views
0

我使用Selenium和webDriver和C#。我想写一些代码来自动访问一个网页。并弹出一个授权窗口(两个输入控件,ex.user应按“管理员”和密码“管理员”,然后点击“确定”按钮)。处理授权弹出窗口

我的代码是:

IAlert alert = driver.SwitchTo().Alert(); 
alert.Sendkeys("admin"); 
alert.Sendkeys("\t");  // it not works. FAILED! 
alert.Sendkeys("admin"); 
alert.Accept();` 

我的问题是如何能够正确输入名称/密码,在弹出的窗口? Selenium如何处理这些弹出窗口?

欢迎任何评论。

+0

它是一个窗口弹出或JavaScript弹出? – Sham 2014-11-05 09:55:23

+0

[Selenium Webdriver and Basic Auth in IE](http://stackoverflow.com/questions/16572956/selenium-webdriver-and-basic-auth-in-ie)也可能出现重复:http://stackoverflow.com/问题/ 5672407/basic-authentication-in-selenium-2-set-up-for-firefoxdriver-chromedriver-and和http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with- selenium-webdriver – krokodilko 2014-11-06 18:36:20

+0

这是一个弹出窗口,我认为。 – 2014-11-10 02:00:50

回答