Copy div contents to variable

I am trying to copy a name from an interaction software we use at the company I work for. I tried this macro:
Chat name.kmmacros (1.6 KB)

But instead of pasting just 'Tracey King" it inputs everything listed on the page. Ideally, I would like just the first name to be copied and set to the "name" variable. Even more ideal I would like it just to use "Tracy" instead of "Tracy King".

That way, when a message is sent, it will be personalized with their name (even though we typically handle 4 chats at one time).

Here is the HTML for the section of the page where it states the name:Screen Shot 2020-08-03 at 2.20.12 PM

Any thoughts on a work around?

participant-name div contains two things: text node with the desired name and a button. To get just the name, try to use .firstChild method.

Also, # is used to specify id attribute, to get an element by class name you need to use .

Try this. hope it works :slight_smile:


I can't test without the actual HTML code, but something like this should work:



Search For:

Replace with:

If this does not work, please post a large block of the HTML code around the target statement using Forum Code Block, with "html" as the language.

This worked beautifully for one of them! But it kept using the same name for all 4 chats :grimacing: I am going to play around with it a bit more to see if I can use a different element name using the information you gave me! Thank you!

This probably means that the same tag.class exists for each post.

Since I don't have your web page, I have used this forum page, which has a similar set of posts with names:

var nameCol = document.querySelectorAll('span.first.username');
var nameList = Array.from(nameCol).map(function(x) {return x.innerText;});

That will return a text list like this:


You should be able to adapt my above script for your needs.

You can easily test this in the Chrome DevTools (right-click on one of the user names and select "inspect").