selenium 上传文件方法补充——SendKeys、win32gui
2021-02-17 05:18
# coding: utf-8 import win32gui # options = webdriver.ChromeOptions() d = webdriver.Firefox()
d.get("https://mp.dayu.com")
d.add_cookie({‘name‘: ‘cna‘,
import win32api
import win32con
from selenium import webdriver
from time import sleep
# options.add_argument(‘disable-infobars‘)
# d = webdriver.Chrome(chrome_options=options)
‘value‘: ‘fhW6ElaKVKF3Gz1‘,
‘domain‘: ‘.dayu.com‘})
d.add_cookie({‘name‘: ‘isg‘,
‘value‘: ‘BIaGbW7sIPskIv6-_W8K5‘,
‘domain‘: ‘.dayu.com‘})
d.add_cookie({‘domain‘: ‘mp.dayu.com‘,
‘name‘: ‘USER_TMP‘,
‘value‘: ‘tuAaJfSaWoKiQutU9mIkyBk‘})
sleep(3)
d.refresh()
sleep(2)
d.find_element_by_xpath("/html/body/div/div/div[1]/ul/li[2]/ul/li[2]/a/span").click()
sleep(5)
d.find_element_by_xpath(‘/html/body/div[1]/div[3]/div/div[2]/div/div/div/div/div[2]/div[1]/div[1]‘).click()
dialog = win32gui.FindWindow(‘#32770‘, u‘文件上传‘)
ComboBoxEx = win32gui.FindWindowEx(dialog, 0, ‘ComboBoxEx32‘, None)
ComboBox = win32gui.FindWindowEx(ComboBoxEx, 0, ‘ComboBox‘, None)
Edit = win32gui.FindWindowEx(ComboBox, 0, ‘Edit‘, None)
button = win32gui.FindWindowEx(dialog, 0, ‘Button‘, None)
sleep(2)
win32gui.SendMessage(Edit, win32con.WM_SETTEXT, 0, r‘C:\Users\DELL\Desktop\vid.mp4‘)
sleep(2)
win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)
文章标题:selenium 上传文件方法补充——SendKeys、win32gui
文章链接:http://soscw.com/index.php/essay/56427.html