selenium + python

in Technology

Automating facebook group posting using selenium webdriver and python

According to Snapagency, $75,000 a year, or 35% percent of all marketing spend on average for companies, almost cost a year of operation. The business owner should build an awareness for their product and service. High and deepen engagement about the business can help to create a continuous brand experience and increase brand visibility. There are many tools and channels to market their business nowadays. One of the methods is to post valuable content on Facebook. But how you can automate this process without wasting your time? You can use this script to automate posting to a specific Facebook group you are member. WARNING: PLEASE USE THIS SCRIPT WITH CAUTIOUS. Facebook will limit your posting if too much often. Take a break between posts and leave some time in between around 10 minutes.

First of all, install python 2.7 into your local machine. Then install selenium.

pip install selenium

Download the chrome driver here and place it in the same directory.

# -*- coding: utf-8 -*-

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import By
from import WebDriverWait
from import expected_conditions as EC

def main():

	# Your Facebook account user and password
	usr = ""
	pwd = ""
	message = "How to learn code fast?\n"
	#set multiple fb groups here
	group_links = [

	chrome_options = webdriver.ChromeOptions()
	chrome_options.add_experimental_option("detach", True)
	chrome_options.add_experimental_option("prefs", { \
		"profile.default_content_setting_values.notifications": 2 # 1:allow, 2:block 

	driver = webdriver.Chrome(executable_path="/your_project_directory/chromedriver")
	driver.implicitly_wait(15) # seconds

	# Go to
	# Enter user email
	elem = driver.find_element_by_id("email")
	# Enter user password
	elem = driver.find_element_by_id("pass")
	# Login

	for group in group_links:

		# Go to the Facebook Group

		# Click the post box

		# Enter the text we want to post to Facebook

		buttons = driver.find_elements_by_tag_name("button")
		for button in buttons:
			if button.text == "Post":

	# driver.close()

if __name__ == '__main__':

Credit to Jorge E. Hernández for his work.

If you looking for a consultation using this script, don’t hesitate to email me nurdin[a]

Write a Comment


  1. first, thanks your code
    I’ve tried this code
    But there was an error.
    i want to post that
    this facebook page is Anyone can post
    however, post_box=driver.find_element_by_xpath(“//*[@name=’xhpc_message_text’]”)
    There seems to be a problem with this part.
    i hope your help