我一直在尝试几天(如果不是几周...)以获得下面的代码工作。我试图实现的是每天运行一个R脚本(通过Windows Server 2008 64位上的批处理脚本和Windows任务计划程序)。 该R脚本将导航到某些网站,登录并调用另存为对话框以将完整页面保存到特定路径。AutoIt和RSelenium导航另存为对话框(Firefox)
如果我在RStudio中的机器上运行我的脚本(Win 8 - 64bit),它就像一个charme - 远程工作,而不是通过Rscript.exe。
问题似乎与SaveAs.au3脚本 - 当我通过RStudio或文件资源管理器调用它时,它可以很好地工作。的相同的R-脚本在批处理文件中执行与:
"C:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe" "C:\JN\abc.R"
,直到系统()命令以及和crahses然后工作,而不会提供任何错误或警告。
也许有人有类似的问题,可以帮助吗?谢谢!
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")