标签: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后再去测试接口,今天终于搞定了
标签:ons css from 利用 号码 response ui自动化 sage selenium
原文地址:http://www.cnblogs.com/mias/p/7093657.html