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

后端 未结 2 2016
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 10:58

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

相关标签:
2条回答
  • 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
    
    0 讨论(0)
  • 2020-12-20 11:31

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

    Facebook SDK for Python

    Python Social Auth documentation

    Facebook OAuth 2 Tutorial

    0 讨论(0)
提交回复
热议问题