我正在使用 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/