Architecture & Requirements

This Tutorial about how to write a Facebook Birthday Bot using Python and Selenium, that checks for today’s birthdays and write to each friend calling him with his first name a certain message.

In this tutorial, you’ll learn:

  • How to use selenium with Python
  • about Gecko Driver
  • How to select web-pages objects and different methods
  • How to build an Facebook bot with Selenium

What You Need

  • Installed Firefox browser
  • Install Gecko: Firefox Web-driver from here
  • Python 3.x
  • Selenium Package from here

Writing the code

To begin, let’s import necessary package, where the most important is Selenium:

Then you need to define the webdriver and make it open Facebook as shown below. Note that at the end of each move, you need to add a pause. "time.sleep(x seconds)".

The next step is to login, and in order to do this, you need to tell the program to pick element by an identifier. Selenium provides many ways to identify page elements using a find_element_by or find_elements_by.

Selenium find_element_by methods

To get the necessary values that Identify each element, you need to copy it from the page html code by inspecting elements.

Right-click on the selected Elements
and copy the Xpath as Shown above

Afterwards, the code shall be written as follows:

Up to this point, the bot should be able to open Facebook and login. The next step shall be to enter the birthdays page where there are lists of today’s birthdays and upcoming ones. the bot later will find the today’s birthdays list to iterate through it.

Finally, creating a loop to iterate within the list, to get the first name and to write birthday wishes, however an exception should be declared in case there isn’t any birthday or if there is no text box (when a friend doesn’t want you talking to him). At the end the bot shall close the session.

And that is it, good luck with your bot. further reading would be the Selenium documentation. also below is the video for this tutorial.

Watch The video: Facebook Birthday Bot using Python and Selenium

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top