这是我的代码, 上传文件的时候无论是
input_field.send_keys(r'D:\MyPython\DownloadGooglePic\save.png')
or
# input_field.send_keys(r'D:/MyPython/DownloadGooglePic/save.png')
都会显示没有找到文件的错误, 请问如何解决这个问题?
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import urllib.request
import datetime
import glob
import os
import re
from PIL import ImageGrab
# im = ImageGrab.grabclipboard()
# im.save('save.png','PNG')
list_of_files = glob.glob('c:/clippic/*') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
latest_file = re.sub(r"/", r"\\", latest_file)
latest_file = re.sub(r"\\", r"/", latest_file)
# if os.path.exists('OCRFile.txt'):
# os.remove('OCRFile.txt')
# with open('OCRFile.txt', 'a') as the_file:
# the_file.write(latest_file)
with open('OCRFile.txt') as the_file:
wordlist = the_file.read().splitlines()
driver = webdriver.Firefox()
url = "http://zhcn.109876543210.com/"
driver.get(url)
input_field = driver.find_element_by_css_selector('div#container input[type="file"]')
input_field.send_keys(r'D:\MyPython\DownloadGooglePic\save.png')
# input_field.send_keys(r'D:/MyPython/DownloadGooglePic/save.png')
1
woshichuanqilz OP 用 Chrome 没有问题, 用 firefox 错误~
|
2
mingyun 2017-08-29 23:02:43 +08:00
进入 DownloadGooglePic 这个目录 然后 input_field.send_keys('save.png') 试试
|