1. 程式人生 > >163郵箱自動化登入實現模組化

163郵箱自動化登入實現模組化

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains

url = 'http://mail.163.com/'
login_text = '登入'


def openbrower():
    webdriver_handle = webdriver.Firefox()
    return webdriver_handle

def  openurl(handle,url):
    handle.get(url)

    
def login_test():
    d = openbrower()
    openurl(d,url)

    d.implicitly_wait(10)
    d.switch_to.frame('x-URS-iframe')

    username_ele = d.find_element_by_name('email')
    username_ele.clear()
    username_ele.send_keys(username)

    pwd_ele = d.find_element_by_name('password')
    pwd_ele.clear()
    pwd_ele.send_keys(pwd)

    d.find_element_by_id('dologin').click()

    try:
        d.find_element_by_link_text('該賬號不格式不正確')
        print('username and pwd error')
    except:
        print('username and pwd right')

if __name__ == '__main__':
    username = '17665324876'
    pwd = '******'

    login_test()

還沒寫完,未完待續