Is it possible to get BTT to click an HTML element? I want to click a particular button, but its position is dynamic so I can’t use that. I’d like to click it by ID, class, or contained text...
Have a look here: Can't execute JS in chrome or Safari
Sorry, couldn't get it to work...
To back up a bit, I'm trying to have a single keystroke:
- Open a particular URL (or better yet, loop through a list of URLs)
- Click on a button identified by the HTML inner-text
var xpath = "//a[contains(text(),'BTT')]";
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
How do I get BTT to accomplish this?
Thanks for the reply, Dirk.
I keep getting a syntax error that seems to indicate that "tell application..." is not valid:
Try this in a AppleScript action:
Here is a script which opens the page and then executes the code.
You may have to adjust the loading time (delay).
You've gone above and beyond. THANKS!
FWIW, the code didn't work at first so I started poking around. When I copied it directly into the console in Safari, it threw an error because it was seeing 'BTT' as an identifier (though the single quotes worked fine in Brave). In Safari, I could use double quotes and it worked, but this refused to compile so I ended up needed to use escaped double quotes and this worked both in Safari & Brave and also compiled correctly in BTT!
Here's what I ended up with:
Here is a all-round script without a fixed delay:
Wow, thanks Dirk!
So if I'm understanding this, it'll be faster yet less likely to "break" if my connection isn't always the same speed, right? I'll definitely give this a shot!
In the screenshot below, I'd like to skip the value underlined in red (because of the "val zero" or "--" boxed in red), but gather the ones underlined in green into a variable. Each <row... on the current tab will have a single value to either skip or add to the array.
The other thing I've been trying to do is somehow reference the same Safari window throughout the script, regardless if I'm currently working with Safari and consequently make a different window "window 1" during while the script is running...
Yes, that's correct.
Tip: You can with JXA debug AppleScript in Safari (you have to activate it in the developer menu and set a "debugger" statement).
As for your second question, I would rethink the approach. Programming a BOT is not easy.
Otherwise, there is a very good tool, which unfortunately has not been updated for years, but still works excellently:
With this tool you can probably do anything you want and without a line of code:
It can also be controlled via AppleScript, but the tool is not cheap.
I hope this helps you a bit.
Dirk, I hear you about the need to rethink the approach...
Some of my main objectives are to have this run as unobtrusively as possible (preferably without so much as a screen flash, since this will be running while I'm using the computer for other things as well!), and also be robust in terms of not breaking if I'm currently using Safari, for example.
Concerning Fake App, do you know whether it's possible to export the workflow as an AppleScript to be used externally to Fake?
Since it looks like it hasn't had any updates in 11 years , I don't really want to consider it if I can't work with the resulting workflow outside of the App itself.
No. The Fake App is a complete standalone Browser App based on the WebKit Framework which means that it always uses the latest browser engine from macOS. The UserAgent can be customized, so the missing update (the last one was in November 2016) only affects the look. But yes, it is over 5 years old.
The big advantage is that you can do everything with Drag & Drop and without Scripting. You can change and test the workflow at any time. It is an "Automator for websites".
I have not seen anything comparable so far.
Yes. The script will be injected when the page is loaded based on what you specify in the header. Here is an example:
// ==UserScript== // @name Wikipedia // @description Dark Mode // @match *://*.wikipedia.org/* // ==/UserScript==
It runs only in the tab in which the page is loaded.
In this case, it would make sense if the whole thing runs in a completely standalone app that you can hide. Take a look at:
With this you can create your own Web Apps and include your own Userscripts and Userstyles. It's from the same developer, but was last updated in October 2018 and costs only $5. It's again based on WebKit and the same applies as I said about Fake.
Unfortunately, I don't know anything better for this either.
PS: For Fake and Fluid there is a trial version available. Userscripts for Safari is free.