Capturing HTML Element's "Copy Selector" and "Copy XPath" values

Hello,

I would like hover over an HTML element and trigger a macro that would capture the element's "Copy Selector" and "Copy XPath" values.

I created a macro to try capture the "Copy Selector" value for "I'm Feeling Lucky" button. But the macro is behaving strangely and I'm not sure why.

In the video, first, I manually captured the "Copy Selector" value, then pasted it into a BBEdit note. This is the correct "Copy Selector" value.

Then, I tried to do the same thing using the macro, "Z_TEST Copy Selector using KM". The macro displayed the value for NamedClipboard copySelector, but the value is different from the value captured manually.

Now, for the strange behavior. In the macro, if I enable 'Display Text “From System Clipboard:…” in Window' (highlighted in orange), then the macro will capture the "Copy Selector" value correctly. (same as the manual process). If I disable 'Display Text “From System Clipboard:…” in Window' (highlighted in orange), then the "Copy Selector" value will be different from the value captured manually.

So, I'm not sure why enabling/disabling the action to display the system clipboard value would change the result of the NamedClipboard copySelector value. I'm so confused here.

Hoping someone knows of a better way to automate capturing an element's "Copy Selector" and "Copy XPath" values.

Any help is appreciated,
ChrisQ

Z_TEST Copy Selector using KM Macro (v10.2)

Z_TEST Copy Selector using KM.kmmacros (8.4 KB)

Copy Selector using KM

the element's "Copy Selector" and "Copy XPath" values.

Bear in mind that elements don't have unique values of this kind.

It's not a one to one mapping – just a language for describing possible routes from the top of a document (or from the whole set of its elements) down to B.

There are typically several (sometimes very many) ways of finding an XPath to a particular object, or of specifying it with a selector expression.

Always more than one road to Rome. The trick is just to choose one that is reasonably efficient, and that's what the Copy As Xpath etc logic will try to do.

Oh, I copy the XPath of the element that way because that's the only way I know of :sweat_smile:.

But any ideas on why the macro behaves different when I enable or disable the action to display the clipboard? It seems very strange.