How to Click a "To-Do" Button in Basecamp? (Code Included)

Hi,

I'm trying to set up a macro that clicks a button in Basecamp (see attached image). I'm not sure how to do this in Keyboard Maestro—can you help?

Below is the code I get from Inspect Element:

<span class="position_reference">
        <button data-behavior="new_todolist" class="action_button">Add a to-do list</button>
        <div class="blank_slate_arrow"></div>
      </span>

There's probably more than one way to solve this. but it may depend upon which browser you are using and you didn't state which one you were using.

KM has groups of actions to support selecting and setting fields in Google Chrome and Apple Safari. It seems that your knowledge of HTML is better than mine so you're more likely to find the appropriate action and set its arguments correctly.

Another approach that could work, under certain conditions, is the Find Image action. You could execute the action to click on the middle of the button by taking a screenshot of the button and placing it into the action. This is not the recommended option but I use it a lot.

There may also be an AppleScript solution but I'm not capable in that language yet.

Have you tried the regular Press a Button function in Keyboard Maestro?

If this button is the ONLY button with a HTML class of "action_button", then this JavaScript should work:

document.querySelector('button.action_button').click();

I cannot guarantee this will work since I do NOT have the full page HTML or URL to test.

You can put this in a KM Execute a JavaScript in Front Browser Action. The page must be fully loaded prior to this Action.

1 Like

I would be pleasantly surprised if that action worked on web pages. I believe it only works on macOS application buttons. Although I admit the wiki says one "The Press a Button action presses a named button in the front window."

There's at least one macro that I have where I've used "Press Button" on a website.

Another one uses

document.getElementById('emailTrigger').click();

but unfortunately the example here does not seem to have an id so I don't think that'll help in this case.

Interesting assertion. I searched around. I found a button which looked like it was being selected when the Press a Button action was executed. Here's the HTML for that button.

<button name="button">Click me</button>

I also found a button for which the Press a Button action did click on it. Here's the HTML code for that button. This proves you were right, it can work on web pages. But most sites I tested did not seem to work. Apparently there are some HTML requirements. It looks like the key HTML code required is <button type="button">

<button type="button" class="block">Block Button</button>

Thanks for posting. I tried the JavaScript in Google Chrome and it didn't work (see attached macro screenshot). FYI: I added the alert just to make the sure the macro ran.

I checked the code and there are loads of buttons/links with the "action_button" class. So I'm not sure how to target this one specifically. If it's useful, the button I'm trying to click is the first button on the page (and always will be).

ClickTest

I wish I could provide the full page HTML, but it's for a client I'm working with. Do you have any other suggestions?

Also, I found a live example of a Basecamp list of To-Dos here: https://public.basecamp.com/1679267/projects/764604/todolists

The only problem is that that page doesn't have the button I'm trying to click. (I think it's a demo page Basecamp uses.) But hopefully it gives you a chance to look at the live code (the rest of the page looks to be the same).

Thanks. I tried the "Press Button" and it didn't work either. Frankly, I'm surprised it's this challenging to do something so simple—but I'm probably missing something.

Nope. To develop the JavaScript, I really need access to the HTML.
Do you perhaps have a test case record/project in Basecamp that does not expose any sensitive data? Or create one. If so, perhaps you could share HTML from that.

Or, if you have a personal test account with dummy data, I could use that.

1 Like

This is easy to do in JavaScript, BUT you have to have access to the full HTML to select the proper HTML element.

Nope. To develop the JavaScript, I really need access to the HTML.
Do you perhaps have a test case record/project in Basecamp that does not expose any sensitive data? Or create one. If so, perhaps you could share HTML from that.

Or, if you have a personal test account with dummy data, I could use that.

Would it help if you viewed this public Basecamp page?

https://public.basecamp.com/1679267/projects/764604/todolists

The button isn't visible, but I see it in the source code. Does that help? (And thank you again for your help!)

I'm no longer able to help because I'm not smart enough to handle this topic now. Compared to JM, I'm a rube, a noob, and a boob. Glad you have him helping you. Basically I'm first line support, JM and others here are second line support, and Peter N Lewis is third line support. I hope nobody is insulted by these assertions.

No worries, Sleepy. I appreciate you trying. :slight_smile:

@cozandeffect1
Why not something simpler?

Just tested this and works in basecamp 3:

1. Pause until conditions
       The screen contains (image)

2. Move and click at center
       Found image center (image)

Yes. Good idea, which I spoke about in the third paragraph of my first post in this thread. :wink:

1 Like

Just tested this and works in basecamp 3:
1.- Pause until conditions
The screen contains (image)
2.- Move and click at center
found image center (image)

Thanks for this; I tried this before (as Sleepy noted) but couldn't get it to work. I wonder if my click placement is off. Could you post a screenshot of your macro? It'd be great to see step-by-step.