How to provide credentials as user input runtime during python automation?

时光怂恿深爱的人放手 提交于 2020-02-15 06:50:25

问题


How to automate the Facebook login without hard-coding my username and password?


回答1:


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



回答2:


You should use Facebook OAuth API, never hard-code password, some references:

Facebook SDK for Python

Python Social Auth documentation

Facebook OAuth 2 Tutorial



来源:https://stackoverflow.com/questions/49275639/how-to-provide-credentials-as-user-input-runtime-during-python-automation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!