借助系统的操作上传文件

import time
from selenium import webdriver
from selenium.webdriver import ChromeOptions, ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as when


class TestDemo:
    def test_01(self):
        url = 'file:///D:/vip%E7%8F%AD%E7%BA%A7/py44/day38_dom%E5%AF%B9%E8%B1%A1/demo_js.html'
        with webdriver.Chrome(executable_path='chromedriver_96.exe') as browser:
            browser.implicitly_wait(5)
            browser.get(url)
            # 通过 python selenium 找到元素
            el = browser.find_element('name', 'mfile')

            # 有很多限制(a, button)
            # el.click()

            # 点击后上传文件的系统控件就出现了,这个鼠标点击和普通的click不一样,非a标签和button标签也能点击

            ActionChains(browser).click(el).perform()
            # el.click()
            # el.send_ke
            # ys(r'D:\vip班级\py44\day38_dom对象\notes.md')
         # 系统自动化使用到的库pywinauto
            from pywinauto import Desktop
            app = Desktop()
            dialog = app['打开']  # 根据名字找到弹出窗口
            dialog["Edit"].type_keys(r'D:\vip班级\py44\day38_dom对象\notes.md')  # 在输入框中输入值
            dialog["Button"].click()

            time.sleep(3)

 

posted on 2021-12-07 17:13  熊猫星人  阅读(285)  评论(0编辑  收藏  举报