0

I have been trying to replace execCommand() since it is obsolete/deprecated, but nothing seems to works. The below code works fine but I am checking if there is a better way?

This is the JS I used btw;

def insert(value, driver):
    script_insert = f'''
        const el = document.querySelector('div[title="Type a message"]');
        el.focus();
        document.execCommand('insertText', false, '{value}');
    '''
    driver.execute_script(script_insert)

    script_send = f'''
            const button = document.querySelector('button[data-tab="11"]');
            button.click()
        '''
    driver.execute_script(script_send)

1 Answers1

0

Based on this answer Document.execCommmand() is not substituted by anything, so you can continue using that until it will not work anymore.

Another option is to find the input tag in the WhatsApp HTML and then use el.value = value.

Last idea could be using an already working and supported library like whatsapp-web.js in Node.JS if this is compatible with your project.

albertopasqualetto
  • 87
  • 1
  • 1
  • 11
  • The input tag method did not work for some reason, the inputs simply don't show up, but also doesn't give any error. The reason I used JS is cause every web driver I tried don't support NON-BMP Unicode characters. Is there a workaround for it? (Tried Edge, Chromium & Firefox drivers). – LogicNotFound Feb 21 '23 at 00:18