0

I'm creating screenshots in my testcases with selenium webdriver, and while these indeed show what is visible in my web application, it doesn't show popups created by the browser.

I have found that in IE in some cases, my app triggers a JS debug popup in IE. This is of course an error and breaks the rest of my test, but the screenshot does not show the error. I presume this is because it's an IE native popup, rather than one trigger by my application.

Is it possible to get this included in the screenshots? I was thinking of maybe creating the screenshot with Robot#createScreenCapture() but obviously that wouldn't show anything useful if the browser is minimized.

So, a few possible solutions: - can you detect if an error message pops up in a browser - is it possible to maximise/focus the browser while running? - can you take screenshots from selenium with the popups showing?

3 Answers 3

1

Selenium will take a screenshot that represents the rendered DOM that the browser shows the end user by intercepting the rendered image that the browser is displaying and taking a copy of it.

It does not take a desktop screenshot so the screenshots shown will not show anything covering the browser window. JavaScript alerts are not part of the rendered DOM so you will not see these in Selenium screenshots.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe because the driver is not with the Alert/Window active?

You could try something like this:

 private void CheckForOtherWindows() { //Check for any other window open if (driver.WindowHandles.Count > 0) { foreach (string window in driver.WindowHandles) { driver.SwitchTo().Window(window); TakeScreenshot(); } } //Check for alert window try { driver.SwitchTo().Alert(); TakeScreenshot(); } catch { //Nothing } } 

This is not tested, not sure if works. Just giving the idea. :)

Edit: To maximize the window is easy:

driver.Manage().Window.Maximize(); 

Hope it helps.

Comments

0

You can use this as below:

FileUtils.copyFile(((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE), new File("E:\\ScreenShot\\screenshot.png")); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.