Click item on Chrome or Safari page by XPath

I am not sure what I am missing but I can’t import this macro to KM. I unzip it and get some files but how do I get it to work within KM? :expressionless:

Hey Nikita,

That’s not macro — it’s a plug-in.

Drag the whole zip file to the Keyboard Maestro Editor icon in the Dock.

-Chris

I cannot get it to work!
version: keyboardmaestro 8.0.3

Error:
Task failed with status 1 in macro "Plug
In" (while executing Click Google Chrome item matching XPath applied to mouse position ).

I don’t know what the plugin is doing, but you can use XPath with the built in Click Browser Link action in Keyboard Maestro 8.

2 Likes

thank you very much

Is this plugin still functional in KM 8.0.5? I’ve installed it and pasted an xPath. I’ve tried all the “applied” option, without success. Wondering if I’m wasting my time. I tried the “Click Browser Link” action but it did not work. The named button I’m trying to click does not appear in the “list” and entering the name does not work.

I am trying to reduce my dependance on clicking at “found images”.

Can you show us the page and button, and the XPath that you are trying to reference it with ?

In the meanwhile, to obtain a valid XPath reference to a clickable element ( e.g. an <a> or <button> element in the HTML) :

  1. In Chrome (better equipped with XPath capture tools than Safari, even if it is Safari that you will target)
    ctrl-click the element of interest, and select Inspect from the contextual menu
  2. In the HTML view which then appears, select the enclosing <a href="..."> or <button> etc element
  3. Ctrl-click again, this time choosing Copy > Copy XPath

The clipboard should now contain an Xpath string like
//*[@id="post_26"]/div/div[2]/div[2]/section/nav/div/button[2]

which you can paste into a Click Browser Link action (the old plugin is now superfluous and no longer maintained).

1 Like

You generally do not need a plugin to click a link via XPath now as XPath support is built in to current versions of Keyboard Maestro.

1 Like

Thanks, both of you, for your response. Below are screenshots of the button and xPath from the code. I'm sorry, I cannot share the actual website without getting approval.

I've tried both the plugin and built-in action without success in this case. Maybe you can tell why by the images shared.

Not all HTML elements respond to clicks.

You would need to identify and target an element which does, for example:

  • any <a> element
  • a <button> element with a function defined for its onclick attribute
  • for style changes, possibly an element with a distinct style defined for :active or :focus

None of these are immediately visible in the element shown as selected in your screenshot, so you may just be clicking an unresponsive element.

Possibly some kind of interactivity is defined for the immediately enclosing div element, for example

I’m embarrassing. The reason the xPath action/plugin was not working is because the Macro “Group” I was working in was disabled. Enabling the group makes quite a difference. :flushed:

1 Like

No problem – happens to us all. Glad you found a solution.

Can I use wildcards?
//*[@id="cb_isExcluded_B000FCK9D6"]/label/input
The B000FCK9D6 bit changes, basically I want to go through the Amazon recommended items pagea and ensure they are all clicked so it doesn't use anything for my rcommendations. There are thousands of them over hundreds of pages and of course it's Amazon so no easy way to work on all of them.

Never mind, done it mainly in AppleScript with a KM wrapper.

1 Like

I'm 4 years late to this particular party, but from this and related posts I've learned to determine the relative Xpath to a folder on a Dropbox web page, based on a string that makes sense to humans.

In short, I can now use this info to forward paid work to my subcontractors more quickly, and that's going to make everyone involved really happy.

Thank you everybody for sharing your knowledge and experience!

@peternlewis what a wonderful contribution you've made!!

2 Likes

I just realized that I've posted in the Plug In Actions area; I'll repost this as a question in the proper place.

My post in case anyone sees it here:

I've figured out the relative Xpath on one type of DropBox page that I work with, but here's one that is giving me some trouble.

I receive an email from my client that provides the plain-English name of a DropBox folder, e.g. "Wav files sent on 12_12_2023 9-30-44 PM." These folders are always in the same parent folder ("Albums to Check").

I want to

  1. use the timestamp string from the email as my means of getting the relative Xpath to the folder,
  2. then (in a few more steps that I have working perfectly) construct a nice one-click task item on a DropBox Paper dashboard.

I have everything working except the relative Xpath, so I'm not sure it's meaningful to post my macro here.

I am leery of posting client pages here, but here is the container HTML for the example folder named above:

<tr class="mc-table-row mc-media-row mc-media-row-border mc-media-row-clickable mc-media-row-culled brws-file-row brws-row-click-selection-method" style="top: 420px;" draggable="false" aria-rowindex="8" aria-label="Name Wav files sent on 12_12_2023 9-30-44 PM, Modified 2023-12-21 3:34 am, Size 0 bytes, " data-filename="Wav files sent on 12_12_2023 9-30-44 PM" tabindex="-1" data-campaigns-element-id="browse-view-list-file"><td class="mc-table-cell mc-media-cell brws-checkbox-cell" style="flex: 1 1 0%;"><div class="brws-vertically-center brws-file-row-checkbox-target" data-testid="brws-file-row-checkbox"><span class="dig-Checkbox"><input class="dig-Checkbox-input" type="checkbox" aria-label="Select item" tabindex="-1" readonly=""><span class="dig-Checkbox-styles"></span><svg aria-hidden="true" width="20px" height="20px" viewBox="0 0 20 20" version="1.1" class="dig-Checkbox-indeterminate-icon" focusable="false"><rect x="5px" y="9px" width="10px" height="2px"></rect></svg><svg class="dig-Checkbox-checked-icon" aria-hidden="true" width="20px" height="20px" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false"><path d="M1 4L4.5 7.5L11 1" stroke="currentColor" stroke-width="2" transform="translate(4, 6)"></path></svg></span></div></td><td class="mc-table-cell mc-media-cell" style="flex: 1 1 0%; min-height: 59px; width: 791px; min-width: 791px; max-width: 791px;"><div class="mc-media-cell-icon"><svg viewBox="0 0 40 40" fill="none" role="img" focusable="false" width="40" height="40" class="dig-ContentIcon brws-file-name-cell-icon dig-ContentIcon--small" data-testid="fallback-file-thumbnail"><path d="M15.002 7.004c.552.018.993.252 1.295.7l.785 2.12c.145.298.363.576.561.779.252.257.633.4 1.156.4H35.5l-.002 18c-.027.976-.3 1.594-.836 2.142-.565.577-1.383.858-2.41.858H8.748c-1.026 0-1.844-.28-2.409-.858-.564-.577-.838-1.415-.838-2.465V7.003h9.502Z" fill="var(--dig-color__foldericon__shadow, #8aa8ca)"></path><path d="M15.002 7.001c.552.018.993.252 1.295.7l.785 2.12c.145.298.363.576.561.779.252.257.633.4 1.156.4H35.5l-.002 16.84c-.027.976-.3 1.754-.836 2.302-.565.577-1.383.858-2.41.858H8.748c-1.026 0-1.844-.28-2.409-.858-.564-.577-.838-1.415-.838-2.465V7l9.502.001Z" fill="var(--dig-color__foldericon__container, #a1c9f7)"></path></svg></div><div class="brws-file-name-container brws-file-name-container--action-ui-inline-star"><div class="brws-file-name-container brws-file-name-container--action-ui-inline-star"><div class="brws-file-name-cell-text brws-vertically-center" draggable="true"><div class="mc-media-cell-text mc-media-cell-text-title"><div class="brws-file-name-cell-title-container"><a class="brws-file-name-cell-filename" href="/home/CK%20(1)/Albums%20to%20Check/Wav%20files%20sent%20on%2012_12_2023%209-30-44%20PM" tabindex="-1"><div aria-describedby="tooltip-ce6b122392962b63" class="_rc-hl-truncated-string__tooltip_1fh0k_28"><span class="brws-file-name-element _rc-hl-truncated-string__container_1fh0k_36" style="display: block;">Wav files sent on 12_12_2023 9-30-44 PM</span></div></a><span class="ax-visually-hidden">Folder</span></div></div><div class="mc-media-cell-text mc-media-cell-text-subtitle"></div></div><div class="brws-file-name-cell-star"><div><button class="star__toggle brws-file-name-star-button" role="button" aria-pressed="false" aria-label="Add to Starred" tabindex="-1" id="star-5b489c43-cd8b-a356-d316-2ddb02cbd41f" aria-labelledby="star-5b489c43-cd8b-a356-d316-2ddb02cbd41f"><span hidden="">Add to Starred</span><svg viewBox="0 0 24 24" fill="none" class="dig-UIIcon dig-UIIcon--standard" width="24" height="24" role="presentation" focusable="false"><path d="m20.836 9.911-6.105-.886L12 3.492 9.27 9.025l-6.106.886 4.43 4.319-.833 6.164L12 17.442l5.239 2.95-.834-6.162 4.43-4.319ZM12 15.72l-3.35 1.886.531-3.924-2.794-2.723 3.878-.564L12 6.882l1.735 3.514 3.878.563-2.795 2.724.532 3.924L12 15.72Z" fill="currentColor" vector-effect="non-scaling-stroke"></path></svg></button></div></div></div></div></td><td class="mc-table-cell mc-media-cell brws-file-shared-with-cell" style="flex: 1 1 0%; width: 160px; min-width: 160px; max-width: 160px;"><div class="brws-vertically-center brws-shared-with-wrapper"><div class="shared-with-members"><div><span class="dig-Text dig-Text--variant-paragraph dig-Text--size-standard dig-Text--color-standard membership-column-text" data-testid="membership-column-text"><button class="dig-StylelessButton audience-description dig-StylelessButton--pointer" aria-label="2 members [object Object]"><span class="dig-StylelessButton-content"><span class="dig-Text dig-Text--variant-paragraph dig-Text--size-standard dig-Text--color-standard">2 members</span></span></button></span></div></div></div></td><td class="mc-table-cell mc-media-cell mc-media-cell-double-line brws-file-modified-at-cell" style="flex: 1 1 0%; width: 200px; min-width: 200px; max-width: 200px;"><div class="mc-media-cell-content"><div class="mc-media-cell-text mc-media-cell-text-title"><span aria-hidden="true">--</span></div><div class="mc-media-cell-text mc-media-cell-text-subtitle"><span class="dig-Text dig-Text--variant-paragraph dig-Text--size-small dig-Text--color-faint"></span></div></div></td><td class="mc-table-cell mc-media-cell brws-file-size-cell" style="flex: 1 1 0%; width: 130px; min-width: 130px; max-width: 130px;"><div class="mc-media-cell-content"><div class="mc-media-cell-text mc-media-cell-text-title"><span aria-hidden="true">--</span></div></div></td><td class="brws-file-row-inline-action-bar--container"><div class="_container_izxke_1 brws-file-row-inline-action-bar brws-file-row-inline-action-bar--safari" data-testid="inline-action-bar-container" style="margin-left: -200.64px;"><button class="dig-Button dig-Button--opacity dig-Button--standard"><span class="dig-Button-content">Copy link</span></button><button class="dig-IconButton dig-IconButton--transparent dig-IconButton--standard" aria-label="Share"><span class="dig-IconButton-content"><svg viewBox="0 0 24 24" fill="none" class="dig-UIIcon dig-UIIcon--standard" width="24" height="24" role="presentation" focusable="false"><path d="M11 15.5V6.744l-3.484 3.3-1.032-1.088 5.266-4.989 5.266 4.989-1.032 1.088-3.484-3.3V15.5H11Z" fill="currentColor" vector-effect="non-scaling-stroke"></path><path d="M15 13v-1.5h3.5V20H5v-8.5h3.5V13h-2v5.5H17V13h-2Z" fill="currentColor" vector-effect="non-scaling-stroke"></path></svg></span></button><div class="dig-Menu"><div class="dig-ClickOutside"><button class="dig-IconButton dig-IconButton--transparent dig-IconButton--standard" aria-haspopup="true" aria-expanded="false" aria-label="More menu" data-testid="action-bar-overflow"><span class="dig-IconButton-content"><svg viewBox="0 0 24 24" fill="none" class="dig-UIIcon dig-UIIcon--standard" width="24" height="24" role="presentation" focusable="false"><path d="M12 10a1.857 1.857 0 0 0-2 2 1.857 1.857 0 0 0 2 2 1.857 1.857 0 0 0 2-2 1.857 1.857 0 0 0-2-2Zm6 0a1.857 1.857 0 0 0-2 2 1.858 1.858 0 0 0 2 2 1.857 1.857 0 0 0 2-2 1.857 1.857 0 0 0-2-2ZM6 10a1.857 1.857 0 0 0-2 2 1.857 1.857 0 0 0 2 2 1.856 1.856 0 0 0 2-2 1.857 1.857 0 0 0-2-2Z" fill="currentColor" vector-effect="non-scaling-stroke"></path></svg></span></button></div></div></div></td></tr>

And here is a screenshot in case that is helpful; the standard URL highlighted in the screenshot doesn't work for others because it's relative to my personal dropbox – and maybe I can work with the client to change that, but here it is:

Thank you X1,000,000,
CK

ComplexPoint: there we go! Daily drive Firefox but the Alphabet Adware Browser definitely worked :slight_smile:

After using Select Field as a way to cull Click Found Image macros, I soon encountered a link I wanted to click. KBM was unable to see/find or allow me to select via the dropdown in the action. Copy Xpath to the rescue, and your button element tip for helping find the right one.

Without this resource (the forums), it would have been far more challenging to evolve my thought process:

  1. I want to automatically click something on a website / in my browser
  2. Move or Click Mouse is too basic/unintelligent/fragile
  3. I want to click on something that looks like a particular icon
  4. I iteratively test Click At Found Image to click an icon
  5. Click At Found Image is unreliable (the way I set it up!)
  6. I read "better to use high level actions like Press Button" on the Found Image Wiki
  7. Press A Button fails
  8. I find this Click Browser Link via XPath solution

Thanks for helping me shave time off the time shave (XKCD 1205):

1 Like