0

I was working on a script to mention members on WhatsApp groups by JS. All the work stopped when I wanted to change the innerHTML using the .innerHTML property to place a mention HTML block in it instead of writing the names of the members then focus the elemnt and clik on the contact name that pops up.

HTML of the input textbox on WA web

<div 
    class="fd365im1 to2l77zo bbv8nyr4 gfz4du6o ag5g9lrv bze30y65 kao4egtt"
    style="max-height: 7.35em; 
    user-select: text; 
    white-space: 
    pre-wrap; word-break: 
    break-word;" 
    role="textbox"
    spellcheck="false" 
    title="Type a message" 
    data-testid="conversation-compose-box-input" 
    data-tab="10"
    data-lexical-editor="true" 
    contenteditable="true">

    <!-- the inner HTML -->
    <p class="selectable-text copyable-text iq0m558w">Test text</p>
    
</div>

JS to change its inner HTML

var typespace = document
.querySelector('div.fd365im1.to2l77zo.bbv8nyr4.gfz4du6o.ag5g9lrv.bze30y65.kao4egtt');

I have trying accessing the DOM by many ways and all the ways go to Rome and return the right address of the DOM but sruprisingly trying to

typespace.innerHTML = '<p class="selectable-text copyable-text iq0m558w" dir="ltr"><span class="selectable-text copyable-text o0rubyzf" data-app-text-template="​201144292107@c.us​" data-lexical-text="true">@Abdo Eid</span><span class="selectable-text copyable-text" data-lexical-text="true"> </span></p>

doesn't work at all. I noticed that after changing it manally from the HTML and trys to use innerHTML it works as expected.

OS: windows 10 lang: JS browser: Chrome, Firefox both at latest versions

  • I don't quite understand your answer, but I think what you are trying to do is dynamically place some text in the whatsapp message container to then send it. Unfortunatelly to you this is a little more complicated, as whatsapp does some deeper stuff to send the messages and all this stuff. I don't know how it works but I do know it's way more complicated than that, so good luck to you for trying to do that! Sorry if my comment wasn't very useful, but I just wanted to warn you that you are entering a more complicated territory than you think – Osmar Feb 23 '23 at 00:59
  • Thanks for notifying me. I have already handled it using events as WA does but it is drastically slower than what may I find (workaround or so). – عبدو عيد Feb 23 '23 at 01:27
  • I'm glad you found a way to do it. Even though it's slower, it probably is the best, at least without a huge amount of work – Osmar Feb 23 '23 at 01:36
  • did you search before asking this question? [This works](https://stackoverflow.com/a/53465009/13006545) – Traidos Feb 23 '23 at 05:50
  • @Traidos Yes, I have searched a lot. In the question I have stated that I don't want to add more clicks to the steps of the script. – عبدو عيد Feb 23 '23 at 21:45

0 Answers0