The Wayback Machine - https://web.archive.org/web/20241001193808/https://www.geeksforgeeks.org/python-automating-happy-birthday-post-on-facebook-using-selenium/
Open In App

Python | Automating Happy Birthday post on Facebook using Selenium

Last Updated : 23 Nov, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

As we know Selenium is a tool used for controlling web browsers through a program. It can be used in all browsers, OS, and its program are written in various programming languages i.e Java, Python (all versions). 

Selenium helps us automate any kind of task that we frequently do on our laptops, PCs ranging from using Facebook messenger for texting and WhatsApp also, daily tweeting tweets on Twitter, wishing friends “Happy birthday” on Facebook, googling anything we want to learn, and many more task. All these tasks can be automated using selenium in just a small implementation.

Installation: 

  • Go to command prompt and put this is in:
pip install selenium

Let’s learn how to automate the process of wishing a birthday wish on a Facebook friend’s timeline as a post.

The whole process of this automation can be divided as follows : 

  • Log into the Facebook application using credentials like Username and Password.
  • Posting a “Happy Birthday” feed on the timeline of those friends whose birthday is today.

Below are the steps: 

  • Create a browser object and use the get() function to send a request to the website we want to connect/use.
  • Find the elements like username and password input boxes, login button, and using the selenium functions like click(), send_keys(), etc to click on buttons and enter username and password respectively.
  • After that using get() function to send a request to /events/birthdays/ page.
  • At the top of this page, there is a card of “Today’s Birthdays” which shows a friend’s name whose birthday is today along with an input text box to enter any feed on their timeline.
  • Using the XPATH of these input text boxes we will send our feed i.e., “Happy Birthday” using the send_keys() function of selenium.
  • Close the browser.

NOTE: Make a separate test.txt file and put your Facebook password in it before the execution of the below program.

Below is the implementation:  

Python3




# importing necessary classes
# from different modules
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.chrome.options import Options
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
import time
 
chrome_options = webdriver.ChromeOptions()
 
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
browser = webdriver.Chrome("chromedriver.exe")
 
# open facebook.com using get() method
 
# user_name or e-mail id
username = "agrawal.abhi108@gmail.com"
 
# getting password from text file
with open('test.txt', 'r') as myfile:
    password = myfile.read().replace('\n', '')
 
print("Let's Begin")
 
element = browser.find_elements_by_xpath('//*[@id ="email"]')
element[0].send_keys(username)
 
print("Username Entered")
 
element = browser.find_element_by_xpath('//*[@id ="pass"]')
element.send_keys(password)
 
print("Password Entered")
 
# logging in
log_in = browser.find_elements_by_id('loginbutton')
log_in[0].click()
 
print("Login Successful")
 
 
feed = 'Happy Birthday !'
 
element = browser.find_elements_by_xpath("//*[@class ='enter_submit\
       uiTextareaNoResize uiTextareaAutogrow uiStreamInlineTextarea\
                  inlineReplyTextArea mentionsTextarea textInput']")
 
cnt = 0
 
for el in element:
    cnt += 1
    element_id = str(el.get_attribute('id'))
    XPATH = '//*[@id ="' + element_id + '"]'
    post_field = browser.find_element_by_xpath(XPATH)
    post_field.send_keys(feed)
    post_field.send_keys(Keys.RETURN)
    print("Birthday Wish posted for friend" + str(cnt))
 
# Close the browser
browser.close()




Previous Article
Next Article

Similar Reads

Automating Google meet using selenium in Python
Prerequisites: Selenium Python basics, Browser Automation using Selenium Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. Sel
3 min read
Program to print Happy Birthday
After a lot of programming algorithms, it's my turn to wish for a programmer friend. Send this code to your coder friend and give him/her a surprise on his/her birthday! C/C++ Code // CPP program to print Happy Birthday #include<bits/stdc++.h> using namespace std; int main() { // Print first row char ch = '@'; for(int i=1; i<=34; i++) { if
8 min read
Wishing Happy Birthday in German - Best 7 Different Ways
In today’s interconnected world, expressing birthday wishes in different languages is a heartfelt gesture that transcends cultural boundaries. Whether you’re a language learner, a global traveler, or someone who wants to built multicultural connections, knowing how to wish "Happy Birthday" in German elevates your greeting. The most common ways of w
7 min read
How to Say Happy Birthday in Spanish
Happy Birthday in Spanish: Another lap around the sun accomplished! We all like to feel special on our birthdays and be celebrated by our loved ones. If you have a Spanish-speaking friend who is having a birthday, you should make them feel extra special by wishing them a happy birthday in Spanish! In today’s post, we will learn how to say happy bir
5 min read
100+ Happy Birthday Wishes: Sweet Quotes & Message ideas
Birthday is the most important day in anyone's life. So wishing your friends, relatives, or colleagues a Happy birthday will make the bond super strong. We have crafted the Top 100 Happy Birthday wishes that you can share on the eve with your friends, partner, or any colleague. Happy Birthday WishesShare these Happy birthday wishes to wish someone
14 min read
Happy Diwali 2024 Date, Quotes, Greetings, Wishes, WhatsApp Facebook Status
Diwali Wishes 2024: Diwali is a major Hindu and Sikh festival in India. Diwali is celebrated annually in the Hindu lunisolar months of Ashvin and Kartika during late October or early November. This year, Diwali 2024 will be celebrated on 01 November 2024. Table of Content When Diwali is celebratedDiwali 2024 DateHistory of DiwaliHow is Diwali Celeb
15+ min read
Automating Scrolling using Python-Opencv by Color Detection
Prerequisites: OpencvPyAutoGUI It is possible to perform actions without actually giving any input through touchpad or mouse. This article discusses how this can be done using opencv module. Here we will use color detection to scroll screen. When a certain color is detected by the program during execution the screen starts to scroll on its own. App
2 min read
How to auto like all the comments on a facebook post using JavaScript ?
In this article, we are going to learn how to like all the comments on a Facebook post automatically. Many times we want to like all the comments of friends on our post or on any other's post, so this script helps us to save time and effort by automatically liking all the comments on the post. Approach: Make variable comments that points to an arra
2 min read
Auto comment on a facebook post using JavaScript
In this article, we are going to learn how to comment automatically on a Facebook post. You can use this method to wish your friends a happy birthday or just comment on anything. It is useful when you want to comment a number of times on a post. You just need to specify the count and message that will be automatically commented on a time interval.
2 min read
Automating a Google Form Filling Task Using UiPath
Data entry is a very hectic task. Let's take an example we have an Excel(CSV) file and a Google form. And the task is that we have to fill that Google forms for each row/data present in that file. If we have 10 or 20 rows it's ok for us to fill the form but take a scenario where thousands of data present in the file in that condition it's very diff
3 min read
Automating some git commands with Python
Git is a powerful version control system that developers widely use to manage their code. However, managing Git repositories can be a tedious task, especially when working with multiple branches and commits. Fortunately, Git's command-line interface can be automated using Python, making it easier to manage your code and automate common tasks. One p
3 min read
Bulk Posting on Facebook Pages using Selenium
As we are aware that there are multiple tasks in the marketing agencies which are happening manually, and one of those tasks is bulk posting on several Facebook pages, which is very time-consuming and sometimes very tedious to do. In this project-based article, we are going to explore a solution that is on the python selenium library and see how we
9 min read
Create a Facebook Post Box Clone in HTML CSS & JavaScript
We will see how can we implement a Facebook post box clone with the help of HTML, CSS, and JavaScript. A Facebook post is a message or update shared by a user on their profile or page. It typically includes text, photos, videos, or links. Users can tag locations, and friends, express feelings, and set privacy settings. Other users can react, commen
8 min read
Automating File Movement on your system
Imagine a situation like this: You have a folder containing files of multiple types like txt, mp3, etc. You decide to clean up this mess and organize them in a way that images are in one folder and songs in another. Will you be moving them as per file type, i.e. number of moves = number of files. No, I'll not be doing this :). This task could be au
3 min read
Microsoft Azure - Automating Azure Blobs Lifecycle Management
In this article, we will learn how to automatically manage Azure Blobs lifecycles. Azure Blob Storage offers different access tiers to reduce storage costs. A Blob in the hot tier costs the most and can be accessed very fast, while a Blob in the archive tier is cheaper and is slower. Let's use Lifecycle Management to automatically move Blobs betwee
2 min read
Automating API Testing with Postman
Testing the functionality, dependability, and performance of an API is known as API testing. API testing can be done automatically or manually. The technique of automating the execution of API tests with tools is known as automated API testing. This can save time and effort, as well as ensure that APIs are tested more thoroughly. Why Automate API T
5 min read
Pythonic SEO: The Ultimate Guide to Automating SEO Task in 2024 AI era
Are you an SEO? Looking for a way to speed up our SEO Manual Task? As I experienced 2 to 3 years in the SEO domain, Python SEO can solve your problems. Search Engine Optimization (SEO) takes a lot of time, concentration, patience, dedication, and some simple Tricks. Though SEO is a long-term project and never a once-off thing, using some Python Cod
7 min read
Automating Docker Deployments With Ansible
Docker is a tool used to dockerize the application along with its dependencies, on the other hand, Ansible is a tool used to manage configuration and deploy applications on other machines. Here in this guide, I will first discuss what is Docker. Then I will discuss What is Ansible. After this, I will walk you through the steps to deploy and run a n
5 min read
Automating the Machine Learning Pipeline for Credit card fraud detection
Before going to the code it is requested to work on a Jupyter notebook or ipython notebook. If not installed on your machine you can use Google Colab.This is one of the best and my personal favorite way of working on a python script to work on a Machine Learning problem. Previous article: Credit Card Fraud Detection using Python Now, I am consideri
4 min read
Automating AWS Network Firewall Configurations with Terraform
The most crucial aspect in protecting and safeguarding network infrastructure in the landscape of cloud computing is applying security to a network. AWS Network Firewall offers high-performance, fully managed security services that provide flexible protection for all your Amazon VPCs to define, implement, and manage network traffic rules that help
8 min read
Automating Model Deployment: Tools and Strategies for MLOps
In the rapidly evolving field of machine learning (ML), automating model deployment has become a crucial aspect of the MLOps (Machine Learning Operations) lifecycle. Automating the deployment of machine learning models enhances productivity, ensures consistency, and accelerates the transition from development to production. Table of Content Underst
5 min read
Continuous Deployment with Docker Swarm: Automating Container Releases
In software development, specifically for software update and feature addition, it is a very agile world. Continuous Deployment (CD) is crucial and is supported by such practices to automate the frequent delivery of new features and/or updates in coding changes to the production environment with minimal manual involvement. Docker Swarm, a native cl
6 min read
Generate a Random Birthday Wishes using JavaScript
In this article, we are going to learn how to create a webpage that generates random Birthday wishes using HTML, CSS, and JavaScript. Approach: To generate a random birthday wish we will follow the below-given steps. HTML Code: In this section, we will create a basic structure of the HTML file i.e. it contains <html>, <head>, <body
2 min read
Birthday Reminder App using HTML, CSS, and JavaScript
Birthday reminder app helps us to track the upcoming birthdays of our loved ones so that we don't forget to celebrate them. In this tutorial, we will create a simple Birthday Reminder web app using the power of HTML, CSS, and JavaScript. This app allows users to add birthdays by adding names and birthday dates and showing all birthdays in a list vi
5 min read
Automatic Birthday mail sending with Python
Are you bored with sending birthday wishes to your friends or do you forget to send wishes to your friends or do you want to wish them at 12 AM but you always fall asleep? Why not automate this simple task by writing a Python script. The first thing we do is import six libraries: pandasdatetimesmtplibtimerequestswin10toast Apart from this, Also cre
3 min read
Birthday Reminder Application in Python
This app helps in reminding birthdays and notifying your friend's birthdays. This app uses Python and Ubuntu notifications to notify users on every startup of the system. # Python program For # Birthday Reminder Application # time module is must as reminder # is set with the help of dates import time # os module is used to notify user # using defau
2 min read
How to make a Selenium jar file, and how to test using a Selenium jar file?
Creating and testing a Selenium jar file is a crucial step in sharing your Selenium automation projects with others or running your tests independently. A JAR file (Java ARchive) packages all your project's classes and resources into a single, executable file. This allows you to easily distribute and execute your Selenium tests on different machine
3 min read
How to use Selenium and Selenium WebDriver Manager to Login to a Website with Python?
Selenium is an open-source tool that is used for automating the tests carried out on different web browsers. Selenium WebDriver is a web framework that allows executing cross-browsing testing. This article focuses on discussing how to log in to a website with Python using Selenium and Selenium WbDriver Manager. Table of Content What is Selenium?Wha
5 min read
Birthday attack in Cryptography
Prerequisite - Birthday paradox Birthday attack is a type of cryptographic attack that belongs to a class of brute force attacks. It exploits the mathematics behind the birthday problem in probability theory. The success of this attack largely depends upon the higher likelihood of collisions found between random attack attempts and a fixed degree o
6 min read
PyQt5 - Age Nearest Birthday Calculator
In this article we will see how we can create a age nearest birthday calculator. Age nearest calculator is the calculator which is used to get the age nearest to the birth date. Below is how the age nearest calculator looks like Concept : We can get the age nearest birthday by getting the difference between the birth date and the present date with
4 min read