在酱实验室中使用selenium webdriver(Grid)上的java运行applescript

时间:2015-09-30 11:07:19

标签: java macos safari applescript selenium-grid

当我们使用selenium远程网络驱动程序(使用selenium网格)在MAC safari浏览器上启动https URL时,我将面临认证安全问题[显示带有继续的弹出窗口]

要点击“继续”按钮,我编写了苹果脚本并手动运行其工作正常。现在问题是无法在java中运行apple脚本。

我试过以下方式::

获取java.io.IOException:无法运行程序“osascript”:CreateProcess error = 2,系统找不到指定的文件,在运行下面的代码时显示错误

String applescriptCommand = "tell application \"System Events\"\n" + "if (exists of application process \"Safari\") is true then\n" + "tell process \"Safari\"\n" + "if (exists of sheet 1 of window 1) is true then\n" + "delay 1" + "click button \"Continue\" of group 2 of sheet 1 of window 1\n" + "delay 2\n" + "end if\n" + "end tell\n" + "end if\n" + "end tell";
String[] args = {"osascript", "-e", applescriptCommand};
Process process = Runtime.getRuntime().exec(args);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
String lsString;
while ((lsString = bufferedReader.readLine()) != null) {
 System.out.println(lsString);
 } 

尝试使用ScriptEngineManager在“engine.eval(applescriptCommand);”中抛出NullPointerException;

String applescriptCommand = "tell application \"System Events\"\n" + "if (exists of application process \"Safari\") is true then\n" + "tell process \"Safari\"\n" + "if (exists of sheet 1 of window 1) is true then\n" + "delay 1" + "click button \"Continue\" of group 2 of sheet 1 of window 1\n" + "delay 2\n" + "end if\n" + "end tell\n" + "end if\n" + "end tell";
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine");
        try {
            engine.eval(applescriptCommand);
        } catch (ScriptException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

请帮助解决这个问题。

0 个答案:

没有答案