简体   繁体   中英

How to handle HTTP basic Authentication on selenium using C#

I have a problem on my automation testing on selenium using C#. My application use the IP address as a base URL and use HTTP authentication alert message as a login. Then my features i test on my application is the LAN features i need to change the IP address so every time i change the IP address it ask me again the authentication for that application. My Code i use is like this:

On the first run of my application i call this code and it works, it inputs the user name and password on the HTTP Auth textbox.

 SendKeys.SendWait("user");
 SendKeys.SendWait("{TAB}");
 SendKeys.SendWait("pass");
 SendKeys.SendWait("{Enter}");

Then after i call the method for changing the IP, then call this code again.

 SendKeys.SendWait("user");
 SendKeys.SendWait("{TAB}");
 SendKeys.SendWait("pass");
 SendKeys.SendWait("{Enter}");

It's not work anymore, it show me the pop up but not input the user and password. How can i still used that code after i change my IP?

在方法的开头插入一个延迟。

using System.Threading.Tasks ... Task.Delay(5000).Wait();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM