Selenium - 使用Windows任务计划程序与命令行

时间:2022-05-12 02:23:09

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:

我有一个批处理文件,用于启动我使用IEDriverServer的Selenium脚本(用Java编写)。当我从命令行运行该批处理文件时,脚本按预期工作。但是,当我使用Windows任务计划程序运行完全相同的批处理文件时,脚本会在WebDriverWait语句期间超时:

(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:

我找到了这个Stack Overflow帖子:

Selenium runs as scheduled task on Windows Server

Selenium在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.

我已经尝试了IEDriverServer的32位和64位版本。

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.

还值得注意的是,在使用任务计划程序时,每次击键时sendKeys方法大约需要5秒,但在直接运行批处理文件时则不会。

How can I get Selenium to behave the same way using the Task Scheduler as it does when running from the command line?

如何使用任务计划程序使Selenium的行为与从命令行运行时的行为方式相同?

Additional Info:

  • Windows Server 2008 R2
  • Windows Server 2008 R2

  • IEDriverServer version 2.42.0
  • IEDriverServer版本2.42.0

  • Selenium Java version 2.42.2
  • Selenium Java版本2.42.2

1 个解决方案

#1


0  

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.

这是一个建议,创建一个可执行的jar文件(右键单击你的项目并导出为Executable Jar)并尝试直接运行它。我从来没有遇到任何性能问题。

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:

以下是如何实现此目的的简短描述:

  1. Create a new Task
  2. 创建一个新任务

  3. Set the Schedule
  4. 设置时间表

  5. In General Tab, using "Run whether the user is logged in or not" will be great.
  6. 在“常规”选项卡中,使用“运行用户是否登录”将非常棒。

  7. Go to Actions, Click on New and Use setting somewhat like this :
  8. 转到“操作”,单击“新建”和“使用”设置,如下所示:

Selenium  - 使用Windows任务计划程序与命令行

  1. In Conditions edit the Power options (You can also select Network settings if you want)
  2. 在条件中编辑电源选项(如果需要,您也可以选择网络设置)

Selenium  - 使用Windows任务计划程序与命令行

  1. Also, do consider updating the settings as well
  2. 另外,请考虑更新设置

Selenium  - 使用Windows任务计划程序与命令行

Save the task, Right click on task and Run it to check if it works fine.

保存任务,右键单击任务并运行它以检查它是否正常工作。

Hope this is of some help :)

希望这个对你有帮助 :)

#1


0  

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.

这是一个建议,创建一个可执行的jar文件(右键单击你的项目并导出为Executable Jar)并尝试直接运行它。我从来没有遇到任何性能问题。

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:

以下是如何实现此目的的简短描述:

  1. Create a new Task
  2. 创建一个新任务

  3. Set the Schedule
  4. 设置时间表

  5. In General Tab, using "Run whether the user is logged in or not" will be great.
  6. 在“常规”选项卡中,使用“运行用户是否登录”将非常棒。

  7. Go to Actions, Click on New and Use setting somewhat like this :
  8. 转到“操作”,单击“新建”和“使用”设置,如下所示:

Selenium  - 使用Windows任务计划程序与命令行

  1. In Conditions edit the Power options (You can also select Network settings if you want)
  2. 在条件中编辑电源选项(如果需要,您也可以选择网络设置)

Selenium  - 使用Windows任务计划程序与命令行

  1. Also, do consider updating the settings as well
  2. 另外,请考虑更新设置

Selenium  - 使用Windows任务计划程序与命令行

Save the task, Right click on task and Run it to check if it works fine.

保存任务,右键单击任务并运行它以检查它是否正常工作。

Hope this is of some help :)

希望这个对你有帮助 :)