wtfaremyinitials / jxa

Access macOS JavaScript for Automation APIs directly in node
307 stars 10 forks source link

command failed: usr/bin/osascript -l JavaScript. #3

Closed Rup1 closed 7 years ago

Rup1 commented 7 years ago

Hi,

I can't quite get your module to work. I am trying to use it in conjunction with webdriverJS. I have the following code:

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until,
    robot = require('robotjs'),
    key = webdriver.Key,
    Application = require('jxa').Application;

var driver = new webdriver.Builder().forBrowser('chrome').build();

driver.get("http://news.google.com");
driver.manage().window().maximize();

function addTab(){
    var chrome = Application("Chrome");
    var window = chrome.windows[0];
    console.log("The window name is: " + window.name());
    var tab = chrome.Tab({url:"http://www.yahoo.com"});
    window.tabs.push(tab); 
    window.currentTab = tab;    
}

driver.sleep(6000).then(function(){
    addTab();
})

    driver.sleep(20000);
    driver.quit();

If I use jxa-node REPL This works until window.tabs.push(tab) which throws the command failed error. Any idea what's causing this?

wtfaremyinitials commented 7 years ago

Unfortunately due to the nature of how the module works under the hood, only simple JS objects can be passed as arguments. As such, passing a chrome.Tab breaks in..interesting ways.

My other module, osa2, should be able to handle this just fine. Apologies for the confusion!

Rup1 commented 7 years ago

Interesting....will try osa2 thanks!

wtfaremyinitials commented 7 years ago

closing this. if you have any more questions, feel free to reopen or send me an email