利用python+seleniumUI自動化登入擷取cookie後再去測試介面,今天終於搞定了

來源:互聯網
上載者:User

標籤: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後再去測試介面,今天終於搞定了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.