使用c#webbrowser确认web自动化中的对话框
本文关键字:对话框 自动化 web c#webbrowser 确认 使用 | 更新日期: 2023-09-27 18:29:45
我需要自动化具有提交功能的网站。
Submit按钮触发JavaScript函数,该函数触发Confirm对话框。
能够通过以下方式自动点击:HtmlElement.InvokeMember("单击");
但无法在确认对话框中自动执行/给出"确定"。
尝试了不同的方法,但没有成功。
输入键选项也不起作用:HtmlElement.InvokeMember("单击");SendKeys.Send("{ENTER}");
有什么方法可以在c#webbrowser中解决这个问题吗?
希望这能起到神奇的作用:
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;
}
}