6

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.

3
  • Did you try use "HtmlUnit" Web Driver instead of specific browser driver? Commented Jan 13, 2012 at 7:22
  • I do not think testing with the HtmlUnit driver is a viable replacement for testing with a real browser.
    – user246
    Commented Jan 17, 2012 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
    Commented Sep 3, 2013 at 22:54

4 Answers 4

1

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.

1

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

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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