selenium 上传文件未找到文件

2017-08-29 12:09:43 +08:00
 woshichuanqilz

这是我的代码, 上传文件的时候无论是

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')


2091 次点击
所在节点    Python
2 条回复
woshichuanqilz
2017-08-29 12:43:31 +08:00
用 Chrome 没有问题, 用 firefox 错误~
mingyun
2017-08-29 23:02:43 +08:00
进入 DownloadGooglePic 这个目录 然后 input_field.send_keys('save.png') 试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/386575

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX