如何在python自动化期间提供凭据作为用户输入运行时? [英] How to provide credentials as user input runtime during python automation?

查看:178
本文介绍了如何在python自动化期间提供凭据作为用户输入运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

无需硬编码用户名密码 Facebook登录 >您可以使用input()函数从控制台获取用户输入,如下所示:

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

控制台输出:

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

这篇关于如何在python自动化期间提供凭据作为用户输入运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆