How to handle Windows Security alert dialog box using Watin IE

 ̄綄美尐妖づ 提交于 2019-12-22 05:03:59

问题


I am trying to automate a website using WatIN IE. As the website bans the ip after few request .So I am setting a bool ipbanned =true when ip gets bannned. In that case and i wish to change the IP. The SetProxy method successfully changes the ip adress with port. but on next request I am getting this screen :-

Note: - the first red strip shows the ip address and the second one shows the server name

How should I set the username and password in this dialog box from within the program, so that user do not get to see this box and it is set correctly

Below is the code snippet I am using:-

    private void Start_Thread()
    {
        Thread pop = new Thread(populate);
        pop.SetApartmentState(ApartmentState.STA);
        pop.Start();

    }
    bool ipbanned=false;
    private void populate()
    {

            if(ipbanned)
                SetProxy(proxies[0]);

           ///I wish to handle the dialog box here.

            WatiN.Core.Settings.MakeNewIeInstanceVisible = false;
            WatiN.Core.Settings.Instance.AutoMoveMousePointerToTopLeft = false;
            using (IE browser = new IE(URLs.mainurl))
            {
                    ///code
            }
    }
    private void SetProxy(string proxy)
    {
        //code which successfully changes the ip address.

    }

Any help will be deeply appreciated. Thank You :)


回答1:


You have to use AddDialogHandler to handle the dialog boxes.

You can refer the SO question watin-logondialoghandlers-not-working-correctly-in-windows-7 for code samples



来源:https://stackoverflow.com/questions/4276044/how-to-handle-windows-security-alert-dialog-box-using-watin-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!