LinkedInLinkedIn API doesn’t allow you to publish into groups if you are not their administrator. That was done in order to eliminate spamming, but if you are a member of several groups of a similar topic and you want to share some interesting information with all of those groups, you have to do it manually group by group and eventually it becomes tedious. In this post I’ll show you a simple way to automate this process in C# using Selenium WebDriver.

Looking at this LinkedIn Group Submitter’s code, you can learn some useful techniques for using Selenium WebDriver. In this program I use ChromeDriver, and here you can read more about where to get ChromeDriver and how to add it into C# projects.

Let’s start. First of all we need to create and configure a ChromeDriver object:

In this code I add an option to start Google Chrome window maximized. If you want rather to hide the window, you may use the following options instead:

The following line forces the WebDriver to wait for 3 seconds until elements appear on the page instead of throwing an exception immediately. This may be necessary if web elements occur on the page dynamically (LinkedIn website actively uses them):

Now let’s sign in into LinkedIn:

I think this code speaks for itself. First it opens the LinkedIn home page, then it types the user’s email and password (don’t forget to put in your own) and then submits the login form.

Then, since we have logged into LinkedIn, we need to open the group’s page and enter our text into the fields of submit form:

LinkedIn Form

The next piece of code opens LinkedIn Group’s page, clicks on post title (1) and waits until the details area (2) and other elements appear:

Now let’s type the title of our post in:

Note that after typing the title this code clicks on details area (2) and waits 3 seconds until element with id=”share-view” becomes visible. This is necessary to give LinkedIn an opportunity to build a preview with a snippet and featured image from your website if you specified its URL in the title. Like this:

LinkedIn Preview

Note also that the title can’t be longer than 200 characters. If you need to add more text you can type it into the details window in the following way:

After we fill all the fields out, we can submit the form by clicking the submit button (3):

That’s it!

Here is the complete code of this simple LinkedIn Group Submitter for your convenience: