1

I have the following code to click on a button. When I debug it, it goes past the Click() line, and the button is clicked (I can see a new window popping up as expected). However, it then just sits there for a minute, then returns with a time out exception. It doesn't go to the next line of code.

Also, this seems to happen only for this button where a new pop-up window is launched after it's clicked. Other buttons on the page seem to be fine.

Thanks in advance for any insight!

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());

Exception Details:

OpenQA.Selenium.WebDriverException was unhandled by user code HResult=-2146233088 Message=The HTTP request to the remote WebDriver server for URL http://localhost:7055/hub/session/5e7fc81a-ed31-4310-9419-f1e5cc0d1b35/element/%7B96a49e56-d619-4765-b0a7-222f69da23bf%7D/click timed out after 60 seconds. Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.Click() at OCSPortalFramework.Pages.BankPortal.ListFormsPage.ClickAddCustomer() in C:\Src\EPSQA\Regression_Portals\OCSPortal\OCSPortalFramework\Pages\BankPortal\ListFormsPage.cs:line 25 at OCSPortalTests.OCS_146710_Add_Customer.OCS_146710_Add_Customer_Test() in C:\Src\EPSQA\Regression_Portals\OCSPortal\OCSPortalTests\OCS_146710_Add_Customer.cs:line 52 InnerException: HResult=-2146233079 Message=The request was aborted: The operation has timed out. Source=System StackTrace: at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) InnerException:

AngieM
  • 735
  • 6
  • 27

1 Answers1

1

Work around for this is:

try {
button.click();
thread.sleep(300);
}
catch(Exception e) {
//System.out.println("" +e.getMessage());
}
Ranjith's
  • 4,508
  • 5
  • 24
  • 40
  • I tried both of your suggestions but it didn't matter since the exception occurs right AFTER the Click() method, so it doesn't get to to the next line. I updated my question to reflect that. – AngieM May 12 '16 at 13:49
  • try this solution specified here: http://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java – Ranjith's May 12 '16 at 14:01
  • I added the following line (DriverFactory.Instance.SwitchTo().Window(DriverFactory.Instance.WindowHandles.Last());) after the Click method (my C# version of the Java post), but again it didn't matter since the Click() method returns the exception before the code to switch window is hit. – AngieM May 12 '16 at 15:05
  • Try giving sleep time before click(); i mean `thread.sleep(250);` then do `button.click()` – Ranjith's May 12 '16 at 15:55
  • Yes I did that before. Didn't help :(. – AngieM May 12 '16 at 16:04
  • 1
    just add try catch block and it works: for example try { WebElement ele = driver.FindElement(By.Id("lookupimg")); ele.Click(); Thread.Sleep(300); } catch (Exception e) { //Console.WriteLine(e); } and give sleep and it works perfectly (Source:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5071) – Ranjith's May 12 '16 at 16:09
  • Yes that Try Catch works (even though I don't quite understand how that fixes it since the Catch block wasn't even hit)!!! Thanks so much for your help. Can I please send you a thank you gift? :) – AngieM May 12 '16 at 16:18
  • Do you mind editing (or create a new response) so that I can mark it as Answered? Thank you so much again! – AngieM May 12 '16 at 16:21