2017-07-17 82 views
2

我想通过发送用户名和密码使用OpenQA.Selenium.IAlert处理Internet Explorer Windows安全弹出窗口。我需要在这个窗口中按TAB和Enter按钮。键{TAB}发送文本而不是按钮按下。有没有什么方法模拟使用C#的按钮按下这个窗口?如何按Windows安全弹出式窗口中的TAB按钮

代码:

var securityWindow = driver.SwitchTo().Alert(); 
    securityWindow.SendKeys("username"); 
    securityWindow.SendKeys("{TAB}"); 
    securityWindow.SendKeys("Password"); 
    securityWindow.SendKeys("{ENTER}"); 

Windows Security window

+0

见https://stackoverflow.com/questions/4378135/programatically-auto-fill-uac-details – sgmoore

回答

0

试试这个用按键类。

securityWindow.SendKeys(Keys.Tab); 
securityWindow.SendKeys(Keys.Enter); 
+0

无效的SendKeys(字符串keysToSend) OpenQA.Selenium.IAlert 的会员需要串 –

+0

@PavelGalich难道您尝试将该键转换为字符串'Convert.ToString(Keys.Tab)' –

+0

它将发送字符串“Tab”到文本框。 OpenQA.Selenium.IAlert SendKeys它不是System.Windows.Forms SendKeys。这是不同的方法。 –

相关问题