0

I am taking the screenshot of this screen:

enter image description here

but everytime it gives me the following exception:

OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:49644/session/bc1237c6e7484d4c9686555254d3ec70/screenshot timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out. at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) --- End of inner exception stack trace --- at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.GetScreenshot() at specflowPjt.Hooks.TakeScreenshot()

I am getting the above exception at AddScreenshot() method of selenium.

The code i am using works fine everywhere, but giving exception only at this place. May someone please tell me what could be possible reasons behind this & finally how to take the screenshot of this screen.

Few pointers that may help you resolving this:

  1. The screen which I am trying to capture is in loading state. (can we capture the screen which is in the loading state?)

  2. My website is very slow.

  3. I am working on remote machine.

Any help would be greatly regarded. Thanks

AndiCover
  • 1,724
  • 3
  • 17
  • 38

2 Answers2

0

the probable reason is in -

  1. I am working on remote machine.

I would suggest to write your own method for screenshooting or take this:

 public void make_screenshot(String filename){

        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
       try {
        FileUtils.copyFile(scrFile, new File("test-output\\" +filename +".png").getAbsoluteFile());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Maybe this will work and u will find it helpful.

Villa_7
  • 508
  • 4
  • 14
0

Remote machine - we had same difficulties here when testing selenium on remote machine

Regarding taking screenshots issue. There are generally three steps which you have to do:

Step1:

Convert web driver object to TakeScreenshot

TakesScreenshot scrShot =((TakesScreenshot)webdriver);

Step2:

Call getScreenshotAs method to create image file

File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);

Step 3:

Copy file to desiced location:

For more information see link: How to take Screenshot - Guru99

There is already a discussion here: How to take screenshots

But it would be nice to insert your code here. Not just the error message. Because from this point, maybe you should also insert an wait Command (see: ToolsQA ) because your error message is saying that it is getting a timeout after 60 seconds...

Hope the links help in your case. Happy testing!

Daniel Boehm
  • 149
  • 1
  • 1
  • 6