WhatsApp Send API or Click To Chat Automation using Selenium & C#

You may also like...

20 Responses

  1. Victor says:

    Is there a way to send message to group ?, On python is possible, but i’m not sure in .net ?

    • Kaarthik says:

      Hi Victor,

      Yes you can send messages to groups. To send messages to groups you cannot use the “Click to Chat” method.

      “Click to Chat” method is especially for sending messages without saving the phone number in users contact list.

      The whole concept is constructed upon “Selenium“. We can use Selenium to execute all the actions we execute manually in a browser in an automated manner.

      Selenium is supported for Java, C#, Ruby, Python, JavaScript (NodeJs), Perl, PHP, and few other languages. In all these language, the above concept can be replicated.

      To send message to group we usually execute/perform the following actions in WhatsApp Web
      1. Login to WhatsApp Web
      2. Search for the group name
      3. Select the group name and enter the message to the send in chat area
      4. Click on the send button

      You need to write, code to replicate these 4 steps using Selenium in any programming language of your choice supported by Selenium.

      Soon I will come up with articles and examples on Whats App Automation using Selenium and Python.

  2. Hello, is there a way to close the session on web whatsapp. For example, when the program is closing.
    What would the code look like?
    Thank you!

    • Kaarthik says:

      Yes you can logout, WhatsApp web provides you option to logout. It will be two step action.
      1. Find the menu button and click on it
      2. Click on Logout Button

      For both the actions its corresponding element has to be found using Selenium, either by CSS Selector or ID and click the button

      WhatsAppWebLogout

  3. Haytham says:

    I got the following exception
    “_2Uo0Z” not found

  4. Roi Sabah says:

    what about webhooks, how can i get new messages?

    • Kaarthik says:

      This method does not support webhooks. But to have such kind of implementation you have to iterate your code and keep on wait for the incoming messages in the chat window.

  5. can we send multi pal msg with this process i have tried but some errors are come when the second msg
    please tell me how send second msg

    • Kaarthik says:

      Yes, you can send multiple messages, but you need to modify this code a little.

      When you are trying to send the first message you would have already logged in to whats app and your message would be already filled in the text-box if you are using click to chat method.

      In this case you will be just finding the send button using Selenium will click it.

      When it comes to the second message you can avoid the login process of click to chat method and directly find the text box element with Selenium, fill your message and click on Send Button

      • Sir i used the Loop method to pass no. to url the no. is pass but at time of send
        i just pass the link to with go url method
        but second msg link was show but is send error when the next process

        An unhandled exception of type ‘OpenQA.Selenium.NoSuchElementException’ occurred in WebDriver.dll

  6. hello sir please upload one blog on multi pal message sender using the same code
    Thanks you sir in advance i have learn lots from this

  7. but second msg link was show but is send error when the next process

    please check this error

    An unhandled exception of type ‘OpenQA.Selenium.UnhandledAlertException’ occurred in WebDriver.dll

    Additional information: unexpected alert open: {Alert text : }

    (Session info: chrome=79.0.3945.117)

  8. Joop Stringer says:

    The problem is on a PC if you have the windows app installed, it wants to open that, no way to go around it ??

    • Owino says:

      Hello, mine keeps asking login to whats app web and press enter, what could be the problem even after scanning it doesnt go through

  9. Rohit says:

    Hi Dear,

    Thanks for this post and very useful. I am near to the complete the solution, I am getting below code line.

    driver.FindElement(By.Id(“action-button”)).Click(); // Click SEND Buton
    driver.FindElement(By.CssSelector(“button._2lkdt>span”)).Click();//Click SEND Arrow Button

    and its all time asking to open whatsapp web

    Thanks in Advance.
    Rohit

  10. Shahzado says:

    Hi sir i wnana be send a msg multiple person with selenium and C# through whatsapp url 1 msg send done but after then erreo and pop up a msg how can i handle

  11. SPACESOFT SYSTEM says:

    how send whatsapp button message using chromedriver in selenium vb 2019

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: