Selenium+python--登录案例

follower yoyo 

一个网站的登录案例,脚本函数化,用def定位每个函数功能,然后在主函数中调用传参。

发现自己前段时间申请的github密码不记得了,囧~

# coding:utf-8
from selenium import webdriver
import time

def login(driver,user,password):
driver.get("https://github.com/login")
driver.implicitly_wait(10)
driver.find_element_by_name("login").send_keys(username)
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_name("commit").click()

def logout(driver):
time.sleep(1)
driver.find_element_by_css_selector(".HeaderNavlink.name.mt-1").click()
time.sleep(1)
driver.find_element_by_css_selector(".dropdown-item.dropdown-signout").click()
driver.quit()

if __name__ == "__main__":
driver = webdriver.Firefox()
login(driver,username,password)
print("welcome to github")
logout(driver)
posted @ 2019-04-03 09:35  山里姑娘  阅读(245)  评论(0编辑  收藏  举报