Gmail Login Screen - Remove an account

I am trying to click the remove an account button on Gmail’s landing page. It stores the accounts that login and I want to remove accounts after each session.

I am on the page so I don’t need to call Safari but I am wondering if I need to bring it forward using AppleScript because it’s not working.

I tried using the Safari Javascript declaration:
document.getElementById(‘Remove an account’).click()

Nothing happens when I trigger it. Any ideas?

Where did you get the id from?
Best source is to right-click on the account button, and select "inspect".

You can use a Execute a JavaScript in Safari action (KM Wiki).

Yes. I know. That's where I got it.

I don't see any such button on my gmail page.
When I try your JavaScript, it fails, it returns a null object, meaning it is not found.

Please provide screenshots of:

  • The button on the gmail page you want to click
  • The HTML shown by the inspector tool when you right-click on it.

BTW, the best way to test JavaScript in Browser, is to type/paste the script in the JavaScript console and press RETURN.

FWIW, I am using Chrome for this.

Here's what I get:
#view_container > form > div.mbekbe.bxPAYd > div > div > div > ul.EACaeb.Us7fWe.XQoWrb > li > button:nth-child(1)

But the inspector is showing this:

OK, as I suspected, “Remove an account” is NOT the tag “id”. It is the “.textContent”. A HTML element “id” always is defined by a:
id="NameOfid"
I’ve never seen one with spaces in it.

Here’s a real example:

<div id="roster_comm_link" style="display:none"></div>

IAC, I finally found the window you are showing, and once it is the active window, this should work to click the “Remove an account” button:

var btnElem = document.querySelector("button.q4UYxb")
if (btnElem.textContent === "Remove an account") {btnElem.click();}

The function document.querySelector() is a very powerful tool.
For more info see: