Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Code for Facebook Log in and Log Out

20 views
Skip to first unread message

Dako Boran

unread,
Oct 29, 2016, 5:14:56 PM10/29/16
to splinter-users
Hello all,

Just complete a quest ;)

I am new with Python and Splinter as well and I create a task for myself Log in and Log out on Facebook using Python.

Below you can find a code:

# coding=utf-8
from splinter import Browser
import time


browser
= Browser()

#Open Facebook page in browser
browser
.visit('https://www.facebook.com/login/')

#Filling form for username
print 'Fill the username form'
browser
.fill('email','em...@example.com')
time
.sleep(5)

#Filling form for password
print 'Fill the password form'
browser
.fill('pass', 'My-favorite-numbers')
time
.sleep(3)

#Click on "Login button"
print '"Log in" button was clicked'
browser
.find_by_id('loginbutton').click()
time
.sleep(4)

#Click on dropdown list menu
print 'Click on drop-down menu'
browser
.find_by_id('userNavigationLabel').click()

time
.sleep(10)
print 'Countdown to click "Log Out" link'
for i in xrange(10,0,-1):
    time
.sleep(1)
   
print str(i) + ' seconds left to click "Log Out" link'
   
browser
.find_by_text('Log Out').click()

time
.sleep(5)
print 'Countdown to close web browser'
for i in xrange(5,0,-1):
    time
.sleep(1)
   
print str(i) + ' seconds left to close web browser'

browser
.quit()

print 'The web browser is closed. Have nice day!'

It takes about two weeks to understand how to do it. Most of the time I was saying "Why this freaking code does not work properly"
Finally I did it and I am happy!

Thank you all!


Reply all
Reply to author
Forward
0 new messages