Thank you DarkPaw, for responding so promptly.
And for the reprimand, justly deserved.
Oops, was not aware the (3) black ticks were so important.
The error (line 11, and in the alternative code in line 13) occurs at the first attempt to find the "Fuel Mix" button.
Error: "First parameter passed to Document constructor must be an object"
function run(input, parameters) {
var Safari = Application('Safari');
Safari.activate();
// Open the AEMO data dashboard (Opens the web page correctly)
Safari.Document().make();
Safari.windows[0].currentTab.url = 'https://www.aemo.com.au/energy-systems/electricity/national-electricity-market-nem/data-nem/data-dashboard-nem';
// Open the AEMO data dashboard (Fails to open the Web page consistently)
// Safari.openLocation('https://www.aemo.com.au/energy-systems/electricity/national-electricity-market-nem/data-nem/data-dashboard-nem');
delay(10); // Wait for page to load
// Click the Fuel Mix tab (target the active <li> in the tabs) (Creates an Error: First parameter passed to Document constructor must be an object)
// Safari.Document(0).doJavaScript("document.querySelector('.tabs .active').click()");
// An Alternative: Click the Fuel Mix tab (fourth tab in the list, creates the Error)
document.querySelectorAll('.tabs-heading li').length;
const tabs = document.querySelectorAll('.tabs-heading li');
if (tabs.length > 3) {
tabs[3].click();
} else
console.error('Not enough tab elements found.');
}
delay(5); // Wait for tab content to load
// Select 48 hrs from the dropdown Safari.Document(0).doJavaScript("document.querySelector('#interval').value = '48H'; document.querySelector('#interval').dispatchEvent(new Event('change'))");
delay(5); // Wait for selection to take effect
// Click the download button
Safari.Document(0).doJavaScript("document.querySelector('.visualisation-icon-button').click()");
return input;
}
Thanks again for your patience.
Robert.