Spread the love

You can log into Facebook using web browser automation tool like Selenium. For fb login facebook , further you could write python script which uses selenium framework.

I know, this might seem very interesting and i know that , you can do it if you follow below steps.

I’ll start from scratch and you will learn below items :

  • What is Selenium?
  • What is Python?
  • How to download and install Python?
  • How to install Selenium for Python?
  • PyCharm IDE
  • Selenium python script for fb login facebook

What is Selenium?

Selenium is used for automating web applications for testing purposes. So, You can use selenium for writing regression tests for any web application. For example, we’ll use Selenium for testing Facebook login functionality .

However, for more information about Selenium , you can read here.

What is Python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.

However,it is very easy to use and you can write selenium scripts using python.

How to download and install Python?

In addition, below video tutorial explains this clearly.


Step 1: You need to go to official site for Python.


Step 2 : You need to select python release version and click on Download button. For example,

Python 3.7.7 March 10, 2020  Download Release Notes

Step 3: After download, you will get .exe file. For example, python-3.7.7-amd64.exe.

Step 4: You need to double click on python-3.7.7-amd64.exe set up and you will get pop up for installation steps.

Step 5: You need to select installation directory and you just need to click on “Next” button and python installation will start and keep on pressing “Next” buttons.

How to check Python version after installation?

You can open command prompt and type below command:

python –version

Most importantly, once you install python , pip also gets installed. You must be thinking , what is pip?

What is PIP?

PIP is package management system in python. PIP is used to install and manage software packages.

Below is the wikipedia link for more information on PIP.


How to install Selenium for Python?

Great, now you have downloaded and installed Python and checked its version as well.

In order to install Selenium for Python , you can use below Steps:

Step 1 : Open command prompt on your machine

Step 2: After that , type below command and press enter subsequently.

pip install selenium

Above command will install all selenium packages on your machine and then you can write selenium scripts in Python subsequently.

PyCharm IDE

Where will you write selenium tests using python ? ūüôā

 To clarify, you can used PyCharm IDE (integrated development environment). This is an editor in which you can create project and therefore , you can write python code.

This comes in two options. In other words, One is license version ( professional )and other one is open source free version ( Community ).

Certainly, I would recommend free version to use for writing selenium python automated tests.

Moreover , PyCharm IDE can be download and installed from its official site as mentioned below :


Selenium python script for fb login facebook

Now, everything is set up on you machine ( Python , Selenium packages , PyCharm IDE ).

Step#1: Open PyCharm IDE

Step#2: Go to File menu and create a new project.

Step#3: Create a python package in side project.

Step#4 : Likewise, Inside package, create a new Python file

Step#5 : further , write below code inside python file.

from selenium import webdriver

# Step 1) Define chromedriver path

chromedriverPath = "C:/Users/My PC/PycharmProjects/seleniumPythonProject/com/mycompany/drivers/chromedriver.exe";
browser = webdriver.Chrome(executable_path=chromedriverPath)

# Step 2) Navigate to Facebook url

# Step 3) Enter you facebook id and password
username = browser.find_element_by_id("email")
password = browser.find_element_by_id("pass")
submit = browser.find_element_by_id("loginbutton")

# Step 4) Click Login

Note : In above code you can set chromedriver path location where chromedriver.exe is kept in your machine.

Moreover, You can download chromedriver exe from below location:

chromedriver official

Facebook Login using Python: FB Login Selenium Python
Facebook Login using Python: FB Login Selenium Python


In conclusion, you can follow below steps.

  • For fb login , you can use selenium with python.
  • You need to have python installed on your machine.
  • You also need PyCharm IDE.
  • Write selenium script to launch chrome browser and navigate to FB login page.
  • Use Selenium to type username and password for facebook login.
  • However, for more information selenium interview questions you can further read here.

References taken for this blog post:

  • https://www.selenium.dev/documentation/en/
  • https://www.python.org/downloads/
  • https://www.jetbrains.com/pycharm/download

Call to Action

If you like this post , please share with your friends to help them and  above all, spread knowledge.

Please comment if you have any questions.

Keep learning , Keep growing!!


Leave a Reply

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