FACEBOOK AUTOMATION

Facebook Posting Using Selenium and C# (.NET Core)

In this article, I will guide you through the process of automating the creation of a new Facebook post using Selenium and C# via .NET Core 3.1.

Oded Olive
Dec 26, 2019 · 2 min read
Image for post
Image for post
Photo by Kon Karampelas on Unsplash

In my previous articles, we went through the process of automating the login process to Facebook (with or without 2FA), so let’s step it up, and post something new automatically.

First off, why would you even want to do that?
Well, there are some scenarios that might come in handy:

For example — let's say you have software that generates some sort of textual content on a schedule (stock analysis? weather statistics? product price tracking?), and you want to share that info/analysis with your Facebook friends, or with your Facebook group automatically.

We will build upon the project we already set up in my previous article, and extend the “FacebookAutomation” class with additional functionality.

First off, let’s add the following method to the FacebookAutomation class:

This method will allow us to implement a “wait” block until a condition is met.
This methodology is superior to an arbitrary “sleep” period, as it will only wait for the minimal time required, and move on to the next automation step right after such condition is met.

The problem with “Arbitrary” sleep statements, is that they are unpredictable — you don’t really know how long you will need to wait until Facebook completes the form validation or until a pop up opens or closes, so you end up using sleep durations that are too long, making the execution of the automation scenario unnecessarily slow.

You will see how to invoke this method in the new method we will be adding next to the “FacebookAutomation” class:

You can see that we are “finding” the post text box, typing in the value into it, and then we wait until the post button is enabled and ready to be clicked on.
Next, we’ll click on the button (using the “ClickAndWaitForPageToLoad” method that already exists in our class — see the previous article) and wait until the submission process is complete before moving on and leaving the method.

Let's tie it all together and call this method in our Main method:

A word of caution — Facebook is cracking down on what it believes to be spam.
Don’t flood Facebook with meaningless content that is obviously computer generated and provide little value to the platform's users.
From my experience, Facebook will usually take action if your posts are reported as spam by other users, but no one really knows how their algorithms work to identify such content automatically (if at all).

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Oded Olive

Written by

Problem solver, creative thinker, terrible tagline writer.

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Oded Olive

Written by

Problem solver, creative thinker, terrible tagline writer.

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store