使用c#webbrowser在Web自动化中确认对话框

时间:2016-01-10 14:26:26

标签: javascript c# automation webbrowser-control browser-automation

我需要自动化具有提交功能的网站。

“提交”按钮会触发一个JavaScript函数,该函数会触发“确认”对话框。

能够自动点击: HtmlElement.InvokeMember("单击&#34);

但是无法在确认对话框中自动执行/给出确定。

尝试了不同的方法,但没有奏效。

输入密钥选项也无效: HtmlElement.InvokeMember("单击&#34); SendKeys.Send(" {ENTER}&#34);

有没有办法在c#webbrowser中解决这个问题?

1 个答案:

答案 0 :(得分:0)

希望这会有所作为:

 public void AcceptAlert()
 {
        IAlert alert = GetAlert();
        alert.Accept();
        WaitForPageLoading(); //this implement by yourself
 }

 public IAlert GetAlert()
 {
        try
        {
             IAlert alert = Driver.SwitchTo().Alert();
             return alert;
        }
        catch (NoAlertPresentException)
        {
             // no alert to dismiss, so return null
             return null;
        }
}