import os.path
from DrissionPage import ChromiumPage
from DrissionPage import ChromiumOptions
# 瀏覽器引數設定
co = ChromiumOptions()
# 瀏覽器啟動路徑
co.set_browser_path(r"D:\Desktop\chrome-win\chrome.exe")
# 瀏覽器最大化
co.set_argument('--start-maximized')
# 開啟瀏覽器
driver = ChromiumPage(co)
# 檔案下載測試
def download():
driver.get('https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Win_x64/494755/')
name = driver.ele('xpath:/html/body/table/tbody/tr[4]/td[2]/a').text
print("待下載檔名", name)
# 瀏覽器下載路徑
driver.set.download_path(r"D:\Desktop\新建資料夾")
# 檔案下載名稱
driver.set.download_file_name(name)
# 下載檔案
driver.ele('xpath:/html/body/table/tbody/tr[4]/td[2]/a').click()
driver.wait.download_begin() # 等待下載開始
driver.wait.downloads_done() # 等待下載結束
download()
def upload():
# 檔案上傳測試
driver.get('https://convertio.co/zh/ico-converter/')
# 設定要上傳的檔案路徑
driver.set.upload_files([os.path.join(r'D:\Desktop\新建資料夾', i) for i in os.listdir(r'D:\Desktop\新建資料夾')])
# 點選觸發檔案選擇框按鈕
driver.ele('xpath:/html/body/div[1]/div/div/div/div[3]/div/div/div/div[1]').click()
# 等待路徑填入
driver.wait.upload_paths_inputted()
# 提交
driver.ele('xpath:.//div[@class="convert-button"]').click()