How to automate the Facebook login without hard-coding my username and password?
To automate the Facebook Login without hard-coding the username and password you can use the input()
function to take the user input from the console as follows :
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("https://www.facebook.com/")
emailid = input("What is your emailid?(Press enter at the end to continue):")
driver.find_element_by_xpath("//input[@id='email']").send_keys(emailid)
password = input("What is your password?(Press enter at the end to continue):")
driver.find_element_by_xpath("//input[@id='pass']").send_keys("password")
driver.find_element_by_xpath("//input[starts-with(@id, 'u_0_')][@value='Log In']").click()
Console Output :
What is your emailid?(Press enter at the end to continue):gomathisubramanian@gmail.com
What is your password?(Press enter at the end to continue):gomathisubramanian
You should use Facebook OAuth API, never hard-code password, some references:
Facebook SDK for Python
Python Social Auth documentation
Facebook OAuth 2 Tutorial