Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

As the question clearly states, I used the screenshot coding in my catch block but it doesn't work.

try {
        LoginPage lp = new LoginPage(driver);

    } catch (Exception er) {
        File scrFile = ((TakesScreenshot) driver)
                        new File(

How to rectify and overcome the problem?

share|improve this question
How doesn't it work? Where is the failure (in the code) that is happening? Are you trying to take a screenshot of if the login page doesn't happen or if the login fails? Also, build a function for your screenshots to avoid repetitive coding. –  PaulDonny Apr 4 '14 at 13:34
yea when it fails or throws some exception i dint get any screenshots at this point even i placed it in catch block. –  Emmanuel Angelo.R Apr 4 '14 at 13:35
Well, this failure would occur as you are logging in. For example, if the page doesn't contain a place to input the username or password, of if id doesn't exist, you would get an exception. Set up a simple System.out.println in your catch to ensure you are actually throwing an error. –  PaulDonny Apr 4 '14 at 13:38
Have you debugged to see what srcFile is to ensure you're looking in the right place? –  Sam Woods Apr 12 '14 at 7:10
how you mention to use debugging as to use debugger or sysout in that line? –  Emmanuel Angelo.R Apr 14 '14 at 4:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.