[英]How to Click OK on chrome popup using Selenium Webdriver C#
JavascriptExecutor应该为您工作。 请注意在单击调用警报的事件之前应执行它。
C#代码
IWebDriver driver; // assume assigned elsewhere
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.confirm = function(msg) { return true; }");
Java代码
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");
注意:-在单击调用警报确认框的事件后,请勿使用它。 上面的代码默认情况下将确认框设置为true表示您接受/单击该页面上所有确认框上的“确定”
希望它能对您有所帮助:)
我找到了一个很好的nuget程序包AutoItX.Dotnet,它将处理chrome中的弹出窗口。 链接NuGet包- https://www.nuget.org/packages/AutoItX.Dotnet/
请使用下面的代码作为参考
//This code snippet will fix your specific issue
AutoItX.WinWait("Untitled - Google Chrome", "", 2);
AutoItX.WinActivate("Untitled - Google Chrome");
AutoItX.Send("{Enter}");
//Use code below to switch between buttons/text boxes within the popup
//And send text to text boxes within the popup
AutoItX.Send("{TAB}");
AutoItX.Send("HelloWorld");
您可能需要进一步测试,以查看需要传递哪些键才能使此代码与您希望与之交互的每个特定弹出窗口无缝运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.