c# - 使用 Selenium 在页面的 onload() 中生成的 JavaScript 警报的解决方法是什么?

标签 c# selenium onload rc javascript

我正在使用 Selenium RC (C#) 自动化表单页面。单击“提交”按钮后,我收到警报“Records Edited Successfully!” '.此警告框的标题是“The page at <a href="http://www" rel="noreferrer noopener nofollow">http://www</a>.******.com says:” '.

但是 Selenium 看不到这个警报。我无法解决它。

这是我尝试过的:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.WaitForPageToLoad("30000");

结果:我收到以下错误:“Selenium.SeleniumException : Timed out after 30000ms

然后我尝试了:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.OpenWindow("", "The page at The page at http://www.******.com says:");
selenium.Close();
selenium.WaitForPageToLoad("30000");

结果:打开了三个窗口(站点、警报和额外窗口)。什么都不会关闭。我收到以下错误:“Selenium.SeleniumException : Timed out after 30000ms

然后我尝试了:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.SelectWindow("The page at The page at http://www.******.com says:");
selenium.Close();
selenium.WaitForPageToLoad("30000");

结果:我收到以下错误:“Could not find window with title 'The page at <a href="http://www" rel="noreferrer noopener nofollow">http://www</a>.******.com says:'

有什么建议吗?请帮助克服这个障碍。

最佳答案

显然,最简单的方法是使用脚本将 alert() 函数重新定义为不弹出对话框的东西。

((JavascriptExecutor) fDriver).executeScript(
  "window.alert = function(msg) { return true; }"
); 

关于c# - 使用 Selenium 在页面的 onload() 中生成的 JavaScript 警报的解决方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4210658/

相关文章:

python - 未找到 Chromedriver 路径? - Selenium - MacOS

javascript - 路由到新页面时 onload 不起作用

javascript - Zoho CRM SDK - 如何在加载时触发功能?

c# - 对不同的 ChromeDriver 实例使用相同的 chrome 配置文件( session )

c# - Windows Xp 上的 Microsoft.Windows.ActCtx

c# - Selenium 无法连接到本地主机以测试 ASP.NET

c# - 等待时发生 StaleElementReferenceException

javascript - Safari 12.1 卸载不触发 javascript

c# - 从 C# 使用 native DLL 的输出参数

c# - 为什么 CLS 要求抛出/捕获异常派生对象?