AutoIt 和 RSelenium 导航另存为对话框 (Firefox)
AutoIt and RSelenium to navigate Save As dialogue (Firefox)
我现在已经尝试了几天(如果不是几周的话......)让下面的代码工作。我想要实现的是每天一个 R 脚本 运行s(通过批处理脚本和 Windows Server 2008 64 位上的 Windows 任务计划程序)。
该 R 脚本应导航到某些网站,登录并调用“另存为”对话框以将完整页面保存到特定路径。
如果我 运行 我的脚本在我的机器上(Win 8 - 64 位)在 RStudio 中它就像一个魅力 - 远程和通过 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")
问题与 Windows Server 2008 R2 有关 - 如果您断开与远程会话的连接,服务器将启动一个屏幕服务器(或类似的),使 AutoIt 脚本无法与 GUI 交互(因为那里不是...)
Windows 服务器中有一些选项可以防止服务器禁用 GUI,但我的脚本仍然不够稳定 运行 几个月...
我现在已经尝试了几天(如果不是几周的话......)让下面的代码工作。我想要实现的是每天一个 R 脚本 运行s(通过批处理脚本和 Windows Server 2008 64 位上的 Windows 任务计划程序)。 该 R 脚本应导航到某些网站,登录并调用“另存为”对话框以将完整页面保存到特定路径。
如果我 运行 我的脚本在我的机器上(Win 8 - 64 位)在 RStudio 中它就像一个魅力 - 远程和通过 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")
问题与 Windows Server 2008 R2 有关 - 如果您断开与远程会话的连接,服务器将启动一个屏幕服务器(或类似的),使 AutoIt 脚本无法与 GUI 交互(因为那里不是...)
Windows 服务器中有一些选项可以防止服务器禁用 GUI,但我的脚本仍然不够稳定 运行 几个月...