Executing JavaScript using selector with a colon

I'm trying to read values from a web page using the "Execute a JavaScript in Safari" actions. This mostly works very well.

But some of the values are identified with id's that have embedded colons. Ex.

"N10:PayElementRunAmount:0"

I know I have to escape the colons so my js to retrieve what I need, (that works in the browser's console), is:

document.querySelector("#N10\\:PayElementRunAmount\\:0").innerText

But my KM action (to save the value in a variable) returns nothing. I've tried varying numbers of backslashes to see if I needed to "escape the escape", so to speak, but no luck with any of it.

Any ideas?

Thanks in advance.

Hi and welcome,
Can you share what you have so far, and the URL or an example

Well, bugger me, it's working now. I swear I tried this already but anyway, I created a new action:

Execute JavaScript in Safari
document.querySelector("#N10\\:PayElementRunAmount\\:0").innerText
Save trimmed results without errors to variable “RunAmount”.
Stop macro and notify on failure.

Now my variable has a value.

I can't share the URL since it's private but here's a snippet of the page:

image

So, problem solved I guess. :smiley:

Thanks

2 Likes

Hey @Swimszoots - you’re learning fast! Especially the part about when @hello asks he expects results :wink:

1 Like