WhatsApp bot chat using selenium
WHATSAPP BOT CHAT USING SELENIUM
SVTH: Nguyễn Khắc Hiếu
GVHD: ThS Nguyễn Huy Anh
Tó m tắt - Trong xã hội phá t triển, giao tiếp đã trở thành một nhu cầu khô ng thể thiếu trong đời
sống xã hội và con người. Với sự phá t triển nhanh chó ng của cô ng nghệ, liên lạc đã được á p dụng
dưới nhiều hì nh thức bao gồm cá c ứng dụng được tạo ra để gọi điện và gửi tin nhắn. Từ đó, nhu cầu
về một ứng dụng có thể gửi tin nhắn hàng loạt đã được tạo ra. Với nền tảng dựa trên ngô n ngữ lập
trì nh Python và các gói và thư viện hỗ trợ cần thiết, WhatsApp Bot Chat là một cách đơn giản nhưng
hiệu quả cao để xử lý yêu cầu gửi tin nhắn hàng loạt. tự động dựa trên cửa sổ trì nh duyệt đồng bộ
hó a với ứng dụng trên điện thoại của bạn. Bài bá o này mô tả cô ng cụ hỗ trợ nhắn tin hàng loạt và tự
động trên WhatsApp cũng như các tính năng và bước của nó .
Abstract - In developed society, communication has become an indispensable need in human
and social life. With the rapid development of technology, communication has been adopted in many
forms including applications created for calling and sending messages. From there, the need for an
application that could send mass messages was created. With a foundation based on the Python
programming language and necessary support packages and libraries, WhatsApp Bot Chat is a simple
but highly efficient way to handle the request for mass messaging. automatically based on a browser
window that syncs with the app on your phone. This paper describes the tool to support batch and
automatic messaging on WhatsApp and its features and steps.
Key words: Python, Selenium, WhatsApp, WebDriver, ChromeDriver, Recursive Function
I. INTRODUCTION
Social networks in general or chat applications in particular are growing strongly in
today's technology age. These applications have attracted millions of people to join and use
them for communication purposes, information exchange as well as many different purposes.
The impact of these applications is enormous in many areas not just communicating with each
other. There are many popular messaging applications such as Messenger, Zalo, WeChat, ..
They are all outstanding and useful applications. WhatsApp is also one of them, WhatsApp is
a cross-platform messaging application, owned by Facebook, allowing you to text for free
with the network available on your mobile device. With the continued growth of messaging
apps, the need for mass messaging has emerged and has become a topic of interest. Issues
such as communication or exchanging information with each other, or even advertising or
business issues are supported and resolved through automated messaging tools.
II.BACKGROUND KNOWLEDGE
1. WhatsApp application
332
Whatsapp is a free messaging app for smart mobile phones. Instead of sending
messages through your carrier, Whatsapp allows you to send messages, pictures, audio or
video over the internet. Whatsapp at first glance is no different from normal messaging
services, but the bottom line of Whatsapp is that it is based on the internet platform. This
makes Whatsapp a lot lower cost compared to other messaging services. Whatsapp's customer
segment is mainly focused on teenagers with features like group chat, voice messaging or
location sharing.
To use Whatsapp, you must first have a smartphone or tablet, a phone sim and the
internet. Whatsapp will use your phone number as the landline account. Therefore, even if
you change to other devices, all your information and data will always be updated according
to this phone number. To use Whatsapp, you only need to spend around 0.99 € per year from
the second year of use. In the first year of use, you get a full range of services for free. In
January 2015, Whatsapp has also updated the plugin on Google Chrome to help users access
it through a computer.
As mentioned above, the first feature of Whatsapp is that users can share their current
location with their friends via text message. They can also sort their friends list and then
quickly send messages to many people at the same time through chat groups. And perhaps the
greatest feature of Whatsapp is that it allows you to contact your friends anywhere in the
world without having to spend text messages or international phone charges like other
messaging services.
2. Selenium
Selenium is a free (open source) automated test suite for web applications across different
browsers and platforms. It is quite similar to HP Quick Test Pro (QTP is now UFT) except
that Selenium focuses on automating web-based applications. Testing that is done using the
Selenium tool is commonly known as the Selenium Test. Selenium is not only a stand-alone
tool but a set of software tools, each of which can meet the different testing needs of an
organization. It has 4 ingredients:
•Selenium Integrated Development Environment (IDE)
•Selenium Remote Control (RC)
• WebDriver
• Selenium Grid
333
Figure 1: Selenium Components
Since Selenium is a set of different tools there are also different developers. Below are
key people who have made a significant contribution to the Selenium project. Mainly
Selenium was created by Jason Huggins in 2004. He was an engineer at ThoughtWorks, then
working on a web application that required frequent testing. After realizing that manual and
repetitive application testing was becoming more and more inefficient, he created a JavaScript
program that could automatically control browser actions. He named this program
"JavaScriptTestRunner." Seeing the potential in this idea to help automate other web
applications, he created the open source JavaScriptRunner, which was later renamed
Selenium Core.
3. Automatic messaging tool
Automatic messaging tools for messaging applications are tools or software capable of
sending messages or transmitting information to a variety of addresses based on phone
numbers quickly and automatically. . This idea has been born for a long time and is still a
topic of interest in the field of social networking in general and messaging applications in
particular. While being used by some individuals and organizations to carry out typical
personal negative purposes such as text message spam, there is no denying that automated
messaging tools also offer certain benefits. above in the matter of sending pure personal
messages as well as in larger areas such as business or advertising. With the use of Python as a
programming language, WhatsApp chat bot was formed on the basis of a simple support tool
but with very good results. Along with the support of Selenium as well as WebDriver, this
tool was able to synchronize on WhatsApp windows in Chrome
334
browser. This paper will describe the project as well as the steps and the
implementation phase of the tool.
III. RELATED WORK
1. DRIFT
In order to prompt website visitors to ask questions, Drift is a popular chatbot program
that can be added to your website. The Drift chatbot will have a scripted conversation with
your leaders if no operators are available and direct them to make a simple appointment with
one of your representatives, but if anyone is available, the chatbot can connect the prospective
customer to one of your representatives to have a synchronous chat conversation about
whatever issues they have.
Chatbots get leads that are not yet curious enough to make a phone call, but who have
questions as they explore your website. Even when live operators are not available, Drift's
ability to answer questions is a significant improvement in lead outreach, resulting in less
delays that are normally common in inbound marketing and other website-traffic-based
marketing strategies.
Drift is proud to be the first conversational marketing site in the world, saying goodbye
to forms and saying hello to conversations. Drift allows companies to find the best leads with
bots in real- time, AKA, the personal assistant of your website. Bots will qualify visitors to
the platform, determine which sales representatives are ideally suited to a particular situation,
and book a meeting - all in one conversation. When it suits them, bots allow you to connect
with consumers, being available 24/7, so that your customers can interact whenever they are
ready.
2. AGENTBOT
AgentBot with Natural Language Comprehension, neural networks, LSTM, Deep
Learning and Machine Learning is a conversational IA-powered bot. In real-time, it chats
with consumers, addresses their needs and offers a 24/7 omnichannel experience.
Companies can communicate with customers in a customized, unstructured and natural
way, thanks to its conversational and semantic engine with multiple IA technologies. In +50
languages, the bot understands informal languages, regionalisms, emojis, and voice messages.
For non-tech workers, its user-friendly platform and easy management make it fine. Without
IT interference, anyone can upload content, edit, create streams and add videos, buttons and
carousels to the responses, among other add-ons.
Assess the efficiency of the bot using Aivo's Analytics tool. Review the key metrics
related to appointments, discussions and experiences transferred, satisfaction and feedback,
and learn from the subjects that your clients are talking about. Day by day, you will also be
335
able to enhance the bot's content depending on what your customers need. Unanswered
questions are gathered and sorted by date and frequency by Aivo's Learning Tool.
IV. METHODOLOGY
1. Recursive function
A recursive function is a function that calls itself during execution. The process can be
repeated many times, outputting the result, and the end of each iteration. Recursive functions
allow programmers to write efficient programs using a minimal amount of code. The
downside is that they can cause infinite loops and other undesirable results if not written
properly. For example, in the above example, the function is terminated if the number is 0 or
less than or greater than 9. If the appropriate instances are not included in a recursive function
to stop execution, it will repeat forever. causes the program to crash or become unresponsive.
Such functions take their name from the recursion mechanism by which a
function's value is determined by applying the same function to smaller arguments. This
process may be illustrated by considering the familiar factorial function x! i.e., the
function which returns the product 1×2×…×x if x>0 and 1 otherwise. An alternative
recursive definition of this function is as follows:
336
fact(0) = 1
fact (x+1) = (x+1) × fact (x)
Such a definition might at first appear circular in virtue of the fact that the value of
fact(x) on the left hand side is defined in terms the same function on the righthand side.
However a characteristic feature of recursive definitions is that they allow for the values of
functions which they describe to be calculated by successively “unwinding” the clause for
x>0 until the clause for x=0 (the so- called base case) is reached. For instance the value of
fact(4) may be calculated using the preceding definition as follows:
fact(4)=4×fact(3)
=4×(3×fact(2))
=4×(3×(2×fact(1)))
=4×(3×(2×1×(fact(0))))
=4×(3×(2×(1×1)))
=24(2)
Understood in this way, the defining equations provide an algorithm for computing
fact(x)—i.e. an effective procedure for calculating its values which can be carried out by a
human or mechanical computing device within a finite number of steps. It is for this reason
that a class of recursive definitions similar to that exemplified by- i.e. the general recursive
functions were first employed as the mathematical model of computation on which recursive
function theory was originally founded.
2. Recursive Functions in Python
In Python, we know that a function can call other functions. It is even possible for the
function to call itself. These types of construct are termed as recursive functions. Recursion is
the process of
determining something in terms of itself. We know that in Python, any function can call
any other function, a function can also call itself. These types of functions which call itself till
the certain condition is not met are termed as recursive functions.
The following image shows the working of a recursive function called “recurse”.
337
3. WebDriver Selenium
Selenium WebDriver is a series of open source APIs used to simplify a web
application's testing. To verify that it works as intended, the Selenium WebDriver tool is used
to automate web application testing. Many browsers, such as Firefox, Chrome, IE, and Safari,
support it. However, we can automate testing only for web applications by using the Selenium
WebDriver. It does not count for applications that are window-based.
It also supports various programming languages for writing test scripts, such as C#,
Java, Perl, PHP and Ruby. The Selenium Webdriver is platform-independent, as various
operating systems such as Microsoft Windows, Apple OS and Linux can use the same code. It
is one of the selenium family elements, which includes Selenium IDE, Selenium Client API,
Selenium Remote Control and Selenium Grid as well.Automation scripts use Selenium
commands for emulating user actions on a web page.
When the automation script is executed, the following steps happen:
• An HTTP request is generated for each Selenium command and sent to the browser
driver.
• To obtain HTTP requests, the browser driver uses an HTTP server.
• The steps needed to execute the Selenium command are decided by the HTTP server.
338
• the implementation steps are executed on the browser
• the execution status is sent back to the HTTP server
• The status is sent back to the automation script by the HTTP server.
V. IMPLEMENTATION & DEMOSTRATION
The first thing to do is to import and install all the necessary packages or libraries for
the project.
Since selenium is already installed in PyCharm, the remaining packages and libraries will
also be fully imported and installed, making sure there are no errors for the project. In
addition to the WebDriver, the project also uses thinkter to support building GUI for the
tool as well as other packages or libraries such as cx_Freezes, functools, pickle, ..
And here is file structure:
The next step is to start up the GUI file so that the tool can be started.
339
It can be seen that a Chrome tab is also launched shortly after, which is the WhatsApp
website. If the website has not been synchronized with the mobile app, just scan the QR
code to confirm login. In GUI has list numbers field for inserting numbers, message field
and image field for sending automatically.
There are three random phone numbers have been selected and tested for automatically
sending messages and accompanying pictures, without adding those numbers to contacts.
340
After sending automatic SMS to all three selected phone numbers, the system will report
successful result as well as error if any.
VI. CONCLUSION & FUTURE WORK
With the background of Python programming language and recursive functions, one of
the most popular and most used programming languages today with packages and libraries,
typically Selenium has handled the item. Project goal, to create a support tool for sending
mass messages automatically on WhatsApp application. The results are positive and
significant. In the future, it is expected that the project will be further developed in the feature
of sending file attachments and, moreover, developing this tool into a mobile application so
that users can more easily use in sending. simple personal messaging or even in advertising or
business.
REFERENCES
341
[6] Selenium assay on ordinary and selenium-rich rice in Jilin area and its effects on
human body by Yahui Lai: https://ieeexplore.ieee.org/document/6028940
[7] SmartDriver: Extension of Selenium WebDriver to Create More Efficient Automated
[8] Testing using selenium web driver by Paruchuri Ramya, Vemuri Sindhura, P. Vidya
[10]
Number of monthly active WhatsApp users worldwide from April 2013 to
February 2016 (in millions).
[11]
The Impact of WhatsApp Messenger Usage on Students Performance in
Tertiary Institutions in Ghana Johnson Yeboah (Lecturer)*,George Dominic Ewur (Lecturer)
Journal of Education and Practice. Available from: https://www.iiste.org/journal-of-
342
Bạn đang xem tài liệu "WhatsApp bot chat using selenium", để tải tài liệu gốc về máy hãy click vào nút Download ở trên
File đính kèm:
whatsapp_bot_chat_using_selenium.pdf

