selenium 上传文件方法补充——SendKeys、win32gui

2021-02-17 05:18

阅读:479

# coding: utf-8

import win32gui
import win32api
import win32con
from selenium import webdriver
from time import sleep

# options = webdriver.ChromeOptions()
# options.add_argument(‘disable-infobars‘)
# d = webdriver.Chrome(chrome_options=options)

d = webdriver.Firefox() d.get("https://mp.dayu.com") d.add_cookie({‘name‘: ‘cna‘,
             ‘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)
             


评论


亲,登录后才可以留言!