Package: whatsapp-web
Simon, a Python Library for WhatsApp Web AutomationBrowser automation for WhatsApp Web service with Python & Selenium.Project consists to allow a user, with whatsapp installed in their phone,
to connect their phone with whatsapp web servicehttps://web.whatsapp.comand
to automate the functionalities a user normally performs when using whatsapp as a chat app.Some functionalities:Reading messagesSending messagesDetecting new messages' notifications.Replying to a specific (making a reference to the message you are replying to) messageIndex:ObjectivesMain Goal & User StoryA) detecting new messagesB) reading new message(s)C) replying a messageD) send a messageCode ExamplesLogin into whatsapp web, check you are logged in & logoutGet all opened chats, go into the chat, read the last 10 messages from your friend and reply to the most recent messageMore examplesInformationMaintainerObjectivesMain Goal & User StorySimon can detect new message(s), read them, analyse it and reply if needed.A) detecting new messagesget simon_opened_chatsinspect available user from top-bottom for notifications (only on available browser screen view)click on the opened chat found with a new message notification iconB) reading new message(s)get contact_chatfind "n unread messages" sectionget first unread msgread and analyse msgC) replying a messageget(hover) the reply icon (on the right-side of the message)click on the reply iconget the reply link("Reply")click the reply link (on browser: it puts cursor on the contact_send_message[message_field])D) send a messageget contact_send_messagewrite messagepress enter to send msg.Code ExamplesFor the library we are using the Page Pattern recommended by the selenium
python library.Login into whatsapp web, check you are logged in & logoutimporttimefromseleniumimportwebdriverfromsimon.accounts.pagesimportLoginPagefromsimon.header.pagesimportHeaderPagefromsimon.pagesimportBasePage# Creating the driver (browser)driver=webdriver.Firefox()driver.maximize_window()# 1. Login#       and uncheck the remember check box#       (Get your phone ready to read the QR code)login_page=LoginPage(driver)login_page.load()login_page.remember_me=Falsetime.sleep(7)# 2. The base page is inherited by all pages#       and here you can check whether any#       page is available on the screen of#       the browser.# we don't need to load the pages as whatsapp# web works as one-page web appbase_page=BasePage(driver)base_page.is_title_matches()base_page.is_welcome_page_available()base_page.is_nav_bar_page_available()base_page.is_search_page_available()base_page.is_pane_page_available()# chat is only available after you open onebase_page.is_chat_page_available()# 3. Logoutheader_page=HeaderPage(driver)header_page.logout()# Close the browserdriver.quit()Get all opened chats, go into the chat, read the last 10 messages from your friend and reply to the most recent messageimporttimefromseleniumimportwebdriverfromsimon.accounts.pagesimportLoginPagefromsimon.chat.pagesimportChatPagefromsimon.chats.pagesimportPanePagefromsimon.header.pagesimportHeaderPage# Creating the driver (browser)driver=webdriver.Firefox()driver.maximize_window()# Login#       and uncheck the remember check box#       (Get your phone ready to read the QR code)login_page=LoginPage(driver)login_page.load()time.sleep(7)# 1. Get all opened chats#       opened chats are the one chats or conversations#       you already have in your whatsapp.#       IT WONT work if you are looking for a contact#       you have never started a conversation.pane_page=PanePage(driver)# get all chatsopened_chats=pane_page.opened_chats# iterating over themforocinopened_chats:print(oc.name)# contact name (as appears on your whatsapp)print(oc.icon)# the url of the imageprint(oc.last_message)print(oc.last_message_time)# datetime objectprint(oc.has_notifications())# are there unread messages?print(oc.notifications)# returns a integer with the qty of new messages, if there are.# 2. Go into the chat#       just click on one to open the chat page#       (where the conversation is happening)first_chat=opened_chats[0]first_chat.click()# 3. Read the last 10 messages from your contactchat_page=ChatPage(driver)msgs=chat_page.messages.newest(10,filterby='contact')formsginmsgs:print(msg.contact)# name (all should be the same)print(msg.date)print(msg.text)print(msg.status)# 4. Reply to the most recent messagemsg=msgs[0]# get the first of the messages query done in previous stepmsg=chat_page.messages.newest(filterby='contact')# Be careful as library can only now reply to text message# Replying to a msg type (video, image, giff, etc) is not implemented yet.msg.reply("This a reply to a specific text msg.")# Logoutheader_page=HeaderPage(driver)header_page.logout()# Close the browserdriver.quit()More examplesFor more functionalities that is offered by the library please check
thetests. Here a couple:Send a multi line messageSend an animated messageGet (If there are any) unread messagesGet the oldest messageGet all messages (order by default: newest)Get most only your recents messagesNote:If you will try to run the test yourself locally, some of them won't
work as some tests are done offline with some html templates that are not available
in the repoInformation:Technology StackPythonLanguageSeleniumBrowser AutomationWhatsapp WebChat ServiceMaintainerGet in touch -–>fantaso