问题
I have a batch file that kicks off my Selenium script (written in Java), which uses the IEDriverServer. When I run that batch file from the command line, the script works as expected. However, when I use the Windows Task Scheduler to run the exact same batch file, the script times out during a WebDriverWait until statement:
(new WebDriverWait(driver, JAVASCRIPT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().equals(BROWSE_PAGE_TITLE);
}
});
I found this Stack Overflow post:
Selenium runs as scheduled task on Windows Server
which suggests that setting the job to "Run whether the user is logged in or not" can fix the problem, but I already have the job set that way.
I have tried both the 32-bit and 64-bit versions of the IEDriverServer.
It is also worth noting that the sendKeys method is taking about 5 seconds per keystroke when using the Task Scheduler, but not when running the batch file directly.
How can I get Selenium to behave the same way using the Task Scheduler as it does when running from the command line?
Additional Info:
- Windows Server 2008 R2
- IEDriverServer version 2.42.0
- Selenium Java version 2.42.2
回答1:
Here is a suggestion, Create an executable jar file (Right click on your project and export as Executable Jar) and try to run that directly instead. I never faced any performance issues with this.
Also, make sure your internet connection is stable, You can use Network tab for those settings before your task runs.
Here is a short description of how to achieve this:
- Create a new Task
- Set the Schedule
- In General Tab, using "Run whether the user is logged in or not" will be great.
- Go to Actions, Click on New and Use setting somewhat like this :
- In Conditions edit the Power options (You can also select Network settings if you want)
- Also, do consider updating the settings as well
Save the task, Right click on task and Run it to check if it works fine.
Hope this is of some help :)
来源:https://stackoverflow.com/questions/24920325/selenium-using-windows-task-scheduler-vs-command-line