如何在python自动化期间提供凭据作为用户输入运行时?

发布于 2021-01-29 14:59:06

如何在不对用户名和密码进行硬编码的情况下自动执行Facebook登录?

关注者
0
被浏览
44
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    要自动进行 Facebook登录 而无需对 用户名密码 进行硬编码,可以使用此input()功能从控制台获取 用户输入
    ,如下所示:

    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()
    

    控制台输出:

    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
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看