9

I have to use whatsapp's click to chat feature for automating the process of sending messages to unsaved numbers. I am currently using selenium to automate the process. I am able to send text messages only for now. I was wondering that it might be possible to send other media files as well like images and videos.

There are 2 unused parameters in my url of click to chat feature, "source" and "data". I thought using these might enable me to send media files but I Haven't been able to do it yet. Example URL for one of my click to chat messages:

https://web.whatsapp.com/send?phone=phoneNumHere&text=Hi&source=&data=

Can anyone confirm that either its possible or not. If its possible what would be the right way to do it?

Thanks

Mukarram Pasha
  • 358
  • 1
  • 4
  • 14
  • Possible duplicate of [Whatsapp Automated Bot not able to search in WhatsApp Contact List](https://stackoverflow.com/questions/51871856/whatsapp-automated-bot-not-able-to-search-in-whatsapp-contact-list) – Shaurya Uppal Aug 26 '18 at 15:36

6 Answers6

15

Similar question: Whatsapp Automated Bot not able to search in WhatsApp Contact List

Send images, videos and docs using Selenium:

//To send attachments
//click to add
driver.findElement(By.cssSelector("span[data-icon='clip']")).click();

//add file path
driver.findElement(By.cssSelector("input[type='file']")).sendKeys("FilePath");

//click to send
driver.findElement(By.cssSelector("span[data-icon='send-light']")).click();
Sers
  • 12,047
  • 2
  • 12
  • 31
2

Coding Working Fine.

//To send attachments
//click to add
driver.findElement(By.cssSelector("span[data-icon='clip']")).click();
//add file to send by file path
driver.findElement(By.cssSelector("input[type='file']")).sendKeys("FilePath");
//click to send
driver.findElement(By.cssSelector("span[data-icon='send-light']")).click();
2

I know it's too late, I just have to add that Whatsapp Web and Whatsapp Desktop accept paste inputs, thus if you can get your picture to the memory (I did it with VB.net took 5 mins to accomplish after a bit of googling) you can just send a paste order and it'll load it in and require and ENTER send key from you.

mortal kab
  • 21
  • 2
1

Part1: Sending messages to unsaved contacts Sending media to unsaved numbers is quite a difficult task but not impossible. You can surely find XPath by text.

Part2: Yes media can be sent to contacts. I have done that in my project link : https://github.com/shauryauppal/PyWhatsapp. By using PyAutoIt you can send Pictures, PDF, Videos to the selected contacts.

Since uploading part is not the automation of web browser we auto windows using AutoIt and select the path of image/video/file to send to the user.

autoit.control_focus("Open","Edit1")
autoit.control_set_text("Open","Edit1",(PATH_OF_IMAGE_TO_SEND) )
autoit.control_click("Open","Button1")

This is just the crux of the implementation. Do refer my repo in case of more understanding.

PS: Don't forget to star repo or give credits.

Check answer Link for more info, where to download AutoIt from.

Shaurya Uppal
  • 3,410
  • 31
  • 31
0

I was having the same issue but right after fixing it, I made a python wrapper so that it helps more people having the same issue.

In case you're interested to explore more about the wrapper, here is a link

https://github.com/Kalebu/alright

Here is how to send a message to media files and message to unsaved contacts

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('255-74848xxxx')
>>> messenger.send_message("I wish you a Merry X-mass and Happy new year ")
>>> messenger.send_picture('path-to-image',"Text to accompany image")

Sending to Multiple unsaved contacts

>>> numbers = ['2557xxxxxx', '2557xxxxxx', '....']
>>> for number in numbers:
        messenger.find_user(number)
        messenger.send_message("I wish you a Merry X-mass and Happy new year "
0

I had to change xpath locations to get working send_pincture function

def send_attachment(self):
    # ...
    sendButton = self.wait.until(
        EC.presence_of_element_located(
            (
                By.XPATH,
                # '//*[@id="app"]/div[1]/div[1]/div[2]/div[2]/span/div[1]/span/div[1]/div/div[2]/div/div[2]/div[2]/div/div/span',
                '//*[@id="app"]/div/div/div[3]/div[2]/span/div/span/div/div/div[2]/div/div[2]/div[2]/div/div/span',
            )
        )
    )
    sendButton.click()
    # ...

def send_picture(self, picture, message):
    # ...
    imgButton.send_keys(filename)
    inp_xpath = "/html/body/div[1]/div/div/div[3]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div[2]/div[1]/div[1]/p"
    input_box = self.wait.until(
    # ...
zforgo
  • 2,508
  • 2
  • 14
  • 22