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.

I'm trying to run a Selenium WebDriver script written in Python on a Windows 7 64-bit box as a scheduled task.

The test works pretty well when run as a batch file from the command prompt, but when run as a scheduled task it fails horribly with errors like ElementNotVisibleExceptions or not being able to find elements.

I've tried running the tests as different users with no change in the outcome. I have tried to modify the TaskScheduler service to interact with the desktop but the option is ghosted.

Does anyone have experience in running tests like these as a scheduled task?

EDIT: I actually ended up figuring this out. Turns out my batch file had some bugs. After debugging it, running the Selenium script through the scheduled task worked fine.

share|improve this question
    
Did you try use "HtmlUnit" Web Driver instead of specific browser driver? –  xeranas Jan 13 '12 at 7:22
    
I do not think testing with the HtmlUnit driver is a viable replacement for testing with a real browser. –  user246 Jan 17 '12 at 19:27
    
I think PhantomJS may serve your purpose better than HtmlUnit. Otherwise, using a browser driver will open the browser in the foreground, which may not be what you intend. –  djangofan Sep 3 '13 at 22:54
add comment

4 Answers 4

Are you using Remote Desktop? If you minimize or close Remote Desktop, it will send a message to Windows indicating nobody is using the computer and therefor the desktop no longer needs to be visible. That might be why your Selenium test can't find the element.

The solution there is to use VNC.

share|improve this answer
add comment

Try to keep machine power settings to always keep monitor and pc on.. Dont let it sleep or lock the PC,or turn off the monitor. It will help for sure

share|improve this answer
add comment

I know that when we run our tests on remote machines with psexec, we have to change the windows service "Interactive Service Detection" to startup "Automatic" and start the service. You might try that.

share|improve this answer
add comment

Scheduled tasks run in a "headless" state so they don't have access to a GUI. I'm assuming that you're using the Firefox WebDriver. Firefox may have a problem starting up in a headless environment.

I think you're better off using the HTMLUnit Driver with Javascript enabled. The trade off you make for running headless is that the Javascript support in HTMLUnit isn't exactly the same as Javascript in FF, IE, Chrome or Safari. Your mileage may vary.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.