Python Automation | Part 8 : WhatsApp Automation |Sending Attachments|Python Selenium Web Automation

    22
    22



    In this video, we are gonna be automating WhatsApp such that we can send bulk messages to groups along with attachments such as images/videos or in other words, a Python script that can send messages to bulk groups along with attachments such as images/videos. The input to the Python script is the group names, the message and the absolute path of the image/video we want to send as an attachment. In short, we will write a cool Python script to send bulk group messages with attachments. This is the second video of the whole 3 video WhatsApp Automation. In the next and last video, we will fix the QR Code issue, that is, we only need to scan the QR Code at the first time we run the Python script. We will leverage Python Selenium for this WhatsApp Bulk Group Message Sending with attachments Automation.

    First Part of WhatsApp Automation : https://www.youtube.com/watch?v=XCcW0NH6M1g&list=PLbasZIkCgHJFbX-kU4vjXsdiHVxGsJzZT&index=8

    Full Playlist : Python Web Automation | Python Selenium Tutorial | Python Automation Tutorial : https://www.youtube.com/playlist?list=PLbasZIkCgHJFbX-kU4vjXsdiHVxGsJzZT

    Project Files – Github Repository : https://github.com/akjasim/python-automation-selenium
    Don’t forget to give a ⭐️ to the repo.

    References :
    Selenium Docs : https://selenium-python.readthedocs.io/
    Selenium Waits Docs : https://selenium-python.readthedocs.io/waits.html
    List Comprehension in Python : https://www.programiz.com/python-programming/list-comprehension

    Subscribe | Code Band

    Other videos in Code Band:
    Python Automation | Part 5 :Instagram Profile Fetch Automation|Python Web Automation|Python Selenium : https://youtu.be/qcTJIqtLYG0
    Python Automation|Part 6 : Gmail Bulk Email Sending Automation|Python Web Automation|Python Selenium : https://youtu.be/A7ZN8JIsGwg
    Build a Weather App in Django | Scrape Weather Data from Google | Beautiful Soup | Python Requests : https://youtu.be/-gzUIPyBRJg
    Python Interview Questions | Python Tricks | Python Tricky Programs | Python Tricks and Hacks : https://youtu.be/I2BAScqkWMU
    Python .env File | Django .env File Example | Python Decouple Django | Django Environment Variables : https://youtu.be/myqfTX9ZbTs
    Django Autocomplete with jQuery UI | AJAX | Search | Filter from Database | Tutorial | Code Band : https://youtu.be/-oLVZp1NQVE
    Django Dependent Drop Down List Example | Integration with Django Forms and Django Form Validations : https://youtu.be/LmYDXgYK1so
    Django Select2 Tutorial | Django Dropdown | Django ajax Dropdown | Django Search and Filter : https://youtu.be/8VYx-cNF1lU
    Django Shell Plus | Advanced Django Shell | Django Shell Commands | Django Shell Tutorial : https://youtu.be/kNFMpfek4Ic
    Django Seed Data into Database Models | Django Faker | Django loaddata | Django Dummy Data : https://youtu.be/QUXvqfN1ENM
    3 Cool Django Features that Django Developers are Not Aware of : https://youtu.be/ljfeFx6QJOM
    Django Custom User Model | Email as Username | Phone as Username | Authentication Example |Code Band : https://youtu.be/SbU2wdPIcaY
    Playlist | Django Authentication | The easiest and actual way of doing it : https://www.youtube.com/playlist?list=PLbasZIkCgHJEQkL2pKTstb4JGrGO6SF9R
    Playlist | Django Relationships | Explained with Example by Code Band : https://www.youtube.com/playlist?list=PLbasZIkCgHJH38p2WkC5GTsgoV_8hlQ4A
    Custom Model Manager & Model QuerySet in Django : https://youtu.be/zQpYokJN34s
    Render Django Form Manually : Make Custom Form with Form Validations – https://youtu.be/PMRalI2M3SY
    Generic Class Based Views in Django | Introduction & Create View in Django | Learn by Example | CRUD : https://youtu.be/RBKjarWdUq4
    How to Deploy Django Project on Heroku for Free : https://youtu.be/V2rWvStauak
    Connect Django with MySQL : https://youtu.be/RCbRjacna20
    Instagram Automation using Python : https://youtu.be/5pIqwVSNzX4
    Top 5 Programming Languages to Learn in 2020 : https://youtu.be/WM0WCMpYCx0

    🙂 You Can Find Me On:
    My Website – https://jasim.tech/
    Linkedin – https://in.linkedin.com/in/akjasim
    Github – https://github.com/akjasim/
    Facebook – https://www.facebook.com/jasimakjasim
    Twitter – https://twitter.com/akjasim
    Instagram – https://www.instagram.com/jasim_ak/

    source

    Previous articleComo criar AMI de ec2 instânce na AWS ? BOTO3 + Python + Lambda
    Next articleПоднимаем Hadoop кластер локально | Скринкасты | Ok #1

    22 COMMENTS

    1. Subscribed!! This worked for me off the bat for sending image. I was confused about how you got the Xpath values because I tried to get the absolute and full xpaths with Inspect, but that did not work. This is important to know because whatsapp dev team will keep changing the UI all the time.

    2. Kaustubh Shah

      1 second ago

      Hello I am getting an error for send button x_path , program runs well till selecting image but it can send :

      NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@data-icon="send"]"}

      (Session info: chrome=87.0.4280.141)

      When I tried with div roll = "button" it shows error not operable element

    3. Hey bro, my bot is stoping after sending the message this is my script:

      from selenium import webdriver

      from selenium.webdriver.common.by import By

      from selenium.webdriver.support.ui import WebDriverWait

      from selenium.webdriver.support import expected_conditions as EC

      from selenium.webdriver.common.keys import Keys

      import pyperclip

      import time

      import sys

      time.sleep(1)

      try:

      if sys.argv[1]:

      with open('groups.txt', 'r', encoding='utf8') as f:

      groups = [group.strip() for group in f.readlines()]

      except IndexError:

      print('Please provide the group name as the first argument.')

      with open('msg.txt', 'r', encoding='utf8') as f:

      msg = f.read()

      browser = webdriver.Chrome('C:/Users/guipo/Desktop/chromedriver_win32/chromedriver.exe')

      browser.maximize_window()

      browser.get('https://web.whatsapp.com/&#39😉

      time.sleep(5)

      for group in groups:

      search_xpath = '//div[@contenteditable="true"][@data-tab="3"]'

      search_box = WebDriverWait(browser, 500).until(

      EC.presence_of_element_located((By.XPATH, search_xpath))

      )

      search_box.clear()

      time.sleep(1)

      pyperclip.copy(group)

      search_box.send_keys(Keys.CONTROL + "v")

      time.sleep(2)

      group_xpath = f'//span[@title="{group}"]'

      group_title = browser.find_element_by_xpath(group_xpath)

      group_title.click()

      time.sleep(5)

      input_xpath = '//div[@contenteditable="true"][@data-tab="6"]'

      input_box = browser.find_element_by_xpath(input_xpath)

      pyperclip.copy(msg)

      input_box.send_keys(Keys.CONTROL + "v")

      input_box.send_keys(Keys.ENTER)

      time.sleep(2)

      try:

      if sys.argv[2]:

      attachment_box = browser.find_element_by_xpath('//div[@title="Anexar"]')

      attachment_box.click

      time.sleep(1)

      image_box = browser.find_element_by_xpath('//input[@accept="image/*,video/mp4,video/3gpp,video/quicktime"]')

      image_box.send_keys(sys.argv[2])

      time.sleep(2)

      except IndexError:

      pass