C# Selenium:打开模式对话框时单击超时

C# Selenium:打开模式对话框时单击超时,c#,selenium,modal-dialog,browser-automation,C#,Selenium,Modal Dialog,Browser Automation,目前,我正在CMS中自动化一个编辑器,其中包括大量选项,如插入链接和更改文本颜色 我面临的问题是,单击其中一个工具栏按钮时,会执行一个javascript命令,启动一个模式对话框 由于某些原因,此模式对话框会导致我的代码挂起“单击”命令,直到手动关闭该命令或单击在60秒后超时 这是我的代码示例 try { // the click that opens the modal dialog driver.FindElement(By.Id("CreatArticle")).Cli

目前,我正在CMS中自动化一个编辑器,其中包括大量选项,如插入链接和更改文本颜色

我面临的问题是,单击其中一个工具栏按钮时,会执行一个javascript命令,启动一个模式对话框

由于某些原因,此模式对话框会导致我的代码挂起“单击”命令,直到手动关闭该命令或单击在60秒后超时

这是我的代码示例

try
{
     // the click that opens the modal dialog
     driver.FindElement(By.Id("CreatArticle")).Click();

     // the code then hangs on the click command above until
     //it times out or the modal dialog is manually closed
     System.Windows.Forms.MessageBox.Show("This message box never shows");
}
catch(exception e)
{
     //this writes the exception to an error log
     testLog("Page creation failed, reason: " + e);
}
我收到的异常消息

> Article creation failed, reason: OpenQA.Selenium.WebDriverException:
> The HTTP request to the remote WebDriver server for URL
> http://localhost:63377/session/adde8cea404a930e9086e1782afcbcf5/element/0.03468421520665288-16/click
> timed out after 60 seconds. ---> System.Net.WebException: The
> operation has timed out    at System.Net.HttpWebRequest.GetResponse() 
> at
> OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest
> request) in
> c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:line
> 142    --- End of inner exception stack trace ---
我还尝试通过js.executeScript命令单击工具栏按钮,结果也一样,但是异常在60秒后执行超时

我建议的一个选项是多线程,当初始线程挂起时,第二个线程处理对话框。selenium是否能够做到这一点,或者我是否可以尝试其他方法

编辑 这是我发现的一个关于我的问题的例子

你能提供一个用户界面屏幕吗?你面对的是什么样的对话框

1例1。如果它像jsAlert,我会尝试:

Alert alert = driver.switchTo().alert();
alert.accept();
2在使用多个浏览器实例并行测试时,另一种方法不被认为是稳健的方法:

//使用类实例处理对话框时按enter键

Robot robot = new Robot();
        robot.delay(2000);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
将提供更多机器人使用案例


希望这对你有用。

我已经找到了解决我自己问题的办法

134 de..。@mingulov.com 大家好

我在Firefox上解决了同样的问题——使用异步点击,例如JavaScript setTimeout

所以不是

元素。单击

使用类似

driver.execute_script'var el=arguments[0];setTimeoutfunction{el.click;},100;',元素


希望它能有所帮助,因为它非常简单-直到这个问题得到解决。

下面是我所面临的问题的一个例子,我正在用c写这篇文章。你知道有什么类似于c中机器人类的东西吗?