How make a program with python and selenium webdriver which will automatically go to the facebook page and log in

in #utopian-io5 years ago

Hi, everyone. May be from my profile you can know that I am an Astrophysicist. But this days I became really interested in programming specially in automation. I know a bit of python. So, I started learning Selenium which is a automation tool we use for Chrome, Firefox or other web browser. So, lets start. First you have to install python, selenium, chrome driver or for Mozilla geckodriver. This are very easy to install. I use linux so I will put the commands. In linux python is install by default. But install pip. The command for installing pip is--

sudo apt install python3-pip
As use pycharm community edition for writing my python programs. So, go to their website and install it. Then comes how to install Selenium. Use the command for linux in the termian.
pip3 install selenium
Now comes how to install the chromedriver. Always remember your chrome version and the chrome driver version has to be the same. Currently the version is 80. You just have to download the driver, unzip it and then you just have to give the path.

Now let us go to the main thing. So, here I will put a screen shot of the program and explain it.
Screenshot from 2020-02-10 00-04-15.png

In the first two line I imported the necessary thing i need for the program to work. The fourth line is for connecting with the cromedriver and put it in a variable. So, that next time we can use it easily.

5 th line is all all out telling to navigate to the facebook page.

In sixth line what we did is we went to the place where facebook asking for your email. we go there and get the xpath. I will explain it with the following screen shots.

Go to the email box and right click and then click on inspect and you will find this--

Screenshot from 2020-02-10 00-11-33.png

Then copy the xpath like this print shot.
Screenshot from 2020-02-10 00-11-46.png

For the next line follow the same steps but with the password box. The next lines I am just telling send the email and password and then click enter. Then run the program. The automation software will take control and it will open your facebook. So, here is how it looks like in a video I made.

So, that is it for today. Have a nice day and enjoy.

Sort:  

This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness!

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider using the steemstem.io app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.