標籤:ons css from 利用 號碼 response ui自動化 sage selenium
#coding=utf-8
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import unittest,time
import requests
#登入模組函數
def login():
u‘‘‘gdtmpd登入‘‘‘
driver=webdriver.Chrome()
driver.get(‘登入地址url‘)
nowhandle=driver.current_window_handle
print "nowhandle:%s"%nowhandle
driver.implicitly_wait(30)
driver.find_element_by_link_text(u‘QQ登入‘).click()
driver.switch_to_frame("ptlogin_iframe") #frame裡面寫frame的id值
time.sleep(5)
driver.find_element_by_id("qlogin_list").find_element_by_css_selector("a[uin=‘這裡是QQ登入號碼‘]").click()
time.sleep(5)
usr=driver.find_element_by_id(‘username-top‘).text
print usr
#擷取與組合儲存cookie
cookie = [item["name"] + "=" + item["value"] for item in driver.get_cookies()]
print cookie
cookiestr = ‘;‘.join(item for item in cookie)
print cookiestr
url_avatar="https://gz.zshlife.com/api/mobile/h5.php?mod=get_my_avatar"
headers={‘cookie‘:cookiestr}
#提供者在headers裡面帶上cookie
response_message=requests.get(url=url_avatar,headers=headers)
res_url=response_message.url
url_name=res_url.split(‘/‘)[-1].split(‘.‘)[0]
print url_name
if __name__ == ‘__main__‘:
login()
利用python+seleniumUI自動化登入擷取cookie後再去測試介面,今天終於搞定了