Selenium学习笔记||十六、浏览器窗口上传系统文件

1. 先安装库

  pip install pypiwin32

2. 使用时导入库

  import win32com.client

  shell = win32com.client.Dispatch("WScript.Shell")

from selenium import webdriver
import win32com.client

driver = webdriver.Chrome(r"D:webdriverchromedriver_73.0.3683.68.exe")
driver.implicitly_wait(20)
driver.get("https://tinypng.com/")
shell = win32com.client.Dispatch("WScript.Shell")

driver.find_element_by_xpath("//*[@class='icon']").click()
shell.Sendkeys(r"D:	aihu.png"+"
")

input('...')
driver.quit()