【问题标题】:Selenium RemoteWebDriver button Click method exception timed out even though the button is clickedSelenium RemoteWebDriver 按钮单击方法异常超时,即使该按钮被单击
【发布时间】:2016-09-08 08:29:06
【问题描述】:

我有下面的代码来点击一个按钮。当我调试它时,它经过 Click() 行,然后单击了按钮(我可以看到一个新窗口按预期弹出)。但是,它会在那里停留一分钟,然后返回超时异常。它不会转到下一行代码。

此外,这似乎只发生在此按钮上,单击后会启动一个新的弹出窗口。页面上的其他按钮似乎没问题。

提前感谢您的任何见解!

var button = DriverFactory.Instance.FindElement(By.Id("ctl07_Customers_OCS_ListForms_btnAddCustomer"));
button.Click(); // A new pop-up window is opened
// Next line of code - It times out before it can hit the following line
DriverFactory.Instance.SwitchTo().Window(DriverFactory.Instance.WindowHandles.Last());

异常详情:

OpenQA.Selenium.WebDriverException 未被用户代码处理 H结果=-2146233088 Message=对 URL http://localhost:7055/hub/session/5e7fc81a-ed31-4310-9419-f1e5cc0d1b35/element/%7B96a49e56-d619-4765-b0a7-222f69da23bf%7D/click 的远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时。 源=WebDriver 堆栈跟踪: 在 OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest 请求) 在 OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数) 在 OpenQA.Selenium.Remote.RemoteWebElement.Click() 在 C:\Src\EPSQA\Regression_Portals\OCSPortal\OCSPortalFramework\Pages\BankPortal\ListFormsPage.cs: 25 中的 OCSPortalFramework.Pages.BankPortal.ListFormsPage.ClickAddCustomer() 在 OCSPortalTests.OCS_146710_Add_Customer.OCS_146710_Add_Customer_Test() 在 C:\Src\EPSQA\Regression_Portals\OCSPortal\OCSPortalTests\OCS_146710_Add_Customer.cs:line 52 内部异常: H结果=-2146233079 Message=请求已中止:操作已超时。 源=系统 堆栈跟踪: 在 System.Net.HttpWebRequest.GetResponse() 在 OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest 请求) 内部异常:

【问题讨论】:

    标签: c# selenium exception-handling timeout remotewebdriver


    【解决方案1】:

    解决方法是:

    try {
    button.click();
    thread.sleep(300);
    }
    catch(Exception e) {
    //System.out.println("" +e.getMessage());
    }
    

    【讨论】:

    • 我尝试了你的两个建议,但没关系,因为异常发生在 Click() 方法之后,所以它不会进入下一行。我更新了我的问题以反映这一点。
    • 试试这里指定的解决方案:stackoverflow.com/questions/19403949/…
    • 我在 Click 方法(我的 C# 版本的 Java 帖子)之后添加了以下行 (DriverFactory.Instance.SwitchTo().Window(DriverFactory.Instance.WindowHandles.Last());),但同样没关系,因为 Click() 方法在切换窗口的代码被命中之前返回异常。
    • 尝试在 click() 之前给睡眠时间;我的意思是thread.sleep(250); 然后做button.click()
    • 只需添加 try catch 块就可以了:例如 try { WebElement ele = driver.FindElement(By.Id("lookupimg")); ele.Click();线程.睡眠(300); } catch (Exception e) { //Console.WriteLine(e); } 并给予睡眠,它完美地工作(来源:github.com/seleniumhq/selenium-google-code-issue-archive/issues/…
    猜你喜欢
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2021-10-28
    • 2019-05-30
    相关资源
    最近更新 更多