简体   繁体   English

如何使用C#在硒上处理HTTP基本身份验证

[英]How to handle HTTP basic Authentication on selenium using C#

I have a problem on my automation testing on selenium using C#. 我在使用C#对硒进行自动化测试时遇到问题。 My application use the IP address as a base URL and use HTTP authentication alert message as a login. 我的应用程序使用IP地址作为基本URL,并使用HTTP身份验证警报消息作为登录名。 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. 然后,我在应用程序上测试的功能是局域网功能,我需要更改IP地址,因此每次更改IP地址时,它都会再次询问该应用程序的身份验证。 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. 在我的应用程序的第一次运行中,我调用此代码,该代码可以工作,它在HTTP Auth文本框中输入用户名和密码。

 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. 然后,在我调用更改IP的方法之后,再次调用此代码。

 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? 更改IP后仍如何使用该代码?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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