V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

selenium 上传文件未找到文件

  •  1
     
  •   woshichuanqilz · 2017-08-29 12:09:43 +08:00 · 2060 次点击
    这是一个创建于 2425 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    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')
    
    
    
    2 条回复    2017-08-29 23:02:43 +08:00
    woshichuanqilz
        1
    woshichuanqilz  
    OP
       2017-08-29 12:43:31 +08:00
    用 Chrome 没有问题, 用 firefox 错误~
    mingyun
        2
    mingyun  
       2017-08-29 23:02:43 +08:00
    进入 DownloadGooglePic 这个目录 然后 input_field.send_keys('save.png') 试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2747 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.