AutoIt和RSelenium导航另存为对话框(Firefox)

时间:2016-03-18 09:16:24

标签: r firefox autoit rselenium

我现在已经尝试了几天(如果不是几周......)以使下面的代码工作。我想要实现的是每天运行一个R脚本(通过Windows Server 2008 64位上的批处理脚本和Windows任务计划程序)。 该R脚本将导航到某些网站,登录并调用“另存为”对话框以将完整页面保存到特定路径。

如果我在我的机器上运行我的脚本(Win 8 - 64bit),它就像一个魅力 - 远程和通过Rscript.exe它不会。

问题似乎与SaveAs.au3脚本有关 - 当我通过RStudio或文件资源管理器调用它时,它运行正常。在批处理文件中执行相同的R脚本:

"C:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe" "C:\JN\abc.R"

一直运行到system()命令,然后在没有提供任何错误或警告的情况下启动。

也许有人有类似的问题并可以提供帮助?谢谢!

3个AutoIt脚本如下:

SaveAs.au3 / exe

ControlFocus("[CLASS:MozillaWindowClass]", "", "")
ControlSend("[CLASS:MozillaWindowClass]", "", "", "^s")

EditName.au3 将从R中可变地编写然后调用

KeyEnter.aut3

ControlFocus("Save as", "", "")
ControlClick("Save as","","[CLASS:Button; INSTANCE:1]")

R脚本如下所示:

# compl is a vector of n href 

if(length(compl) != 0) {
  foreach(i=1:length(compl)) %do% {
    server_check() # checks whether selenium driver is still active and firefox window is open
    remDr$navigate(compl[i])
    Sys.sleep(10)
    login_check() # checks whether login is still active
    Sys.sleep(5)
    print(paste("attempt to save:",compl[i]))
    system('C:\\JN\\SaveAs.exe') # does not matter whether .exe or .au3
    Sys.sleep(3)
    system("cmd", input = c('echo ControlSetText("Save as", "", "[CLASS:Edit; INSTANCE:1]", "") > C:\\JN\\EditName.au3',
                            paste0('echo ControlSend("Save as", "", "[CLASS:Edit; INSTANCE:1]", "',
                                   gsub("/","_",gsub(website_url,"", compl[i])), ".htm",
                                   '") >> C:\\JN\\EditName.au3')))
    Sys.sleep(3)
    system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\EditName.au3')
    Sys.sleep(8)
    system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\KeyEnter.au3')
    Sys.sleep(30)
  }
}
print("Complete save end")

1 个答案:

答案 0 :(得分:0)

问题与Windows Server 2008 R2有关 - 如果从远程会话断开连接,服务器将启动屏幕服务器(或类似),使AutoIt脚本无法与GUI交互(因为没有...)

Windows Server中有一些选项可以阻止服务器禁用GUI,但我的脚本仍然不够稳定,无法自行运行数月......

相关问题