Run applescript using java on selenium webdriver(Grid) in sauce lab

限于喜欢 提交于 2019-12-11 09:56:14

问题


I am facing certification security issue[showing popup with continue] when we launch https URL on MAC safari browser using selenium remote web-driver(using selenium grid)

To click "continue" button, I wrote the apple script and ran manually its working fine. Now the problem is not able to run the apple script in java.

I tried with below ways::

getting java.io.IOException: Cannot run program "osascript": CreateProcess error=2, The system cannot find the file specified, error getting displayed while we running the below code

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);
 } 

Tried with ScriptEngineManager its throwing NullPointerException at "engine.eval(applescriptCommand);"

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();
        }

kindly help on this issue.

来源:https://stackoverflow.com/questions/32864539/run-applescript-using-java-on-selenium-webdrivergrid-in-sauce-lab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!