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
Ctry
V2EX  ›  Python

selenium+python3 上传文件时提示错误: File not found,请各位帮忙找一下原因。

  •  
  •   Ctry · 2018-02-06 16:03:00 +08:00 · 2111 次点击
    这是一个创建于 2242 天前的主题,其中的信息可能已经有所发展或是发生改变。

    上传文件代码如下: browser.find_element_by_xpath('//div[@id="uploadifive_filepathupload"]/input[2]').send_keys(ReadBugFile.FileAddress)

    ReadBugFile 是一个 txt 文件,文件里面的有需要上传的文件路径。然后通过读取这个 txt 文件里面的路径,传入 send_keys()方法。但是提示文件未找到。

    如果直接传入需要上传的文件地址路径,就是正常的。是否与 send_keys()可以接收的参数有关?

    麻烦了解的 V 友指教。感谢!!

    2 条回复    2018-02-06 16:58:08 +08:00
    ClutchBear
        1
    ClutchBear  
       2018-02-06 16:43:09 +08:00
    ReadBugFile 你说是一个 txt 文件, 在 Python 里也就是一个字符串
    字符串哪里来的 FileAddress 方法呢.
    最简单的处理方法:
    把文件里面的路径读取出来, 放到一个变量 file_path 里面
    然后 send_keys(file_path)
    Ctry
        2
    Ctry  
    OP
       2018-02-06 16:58:08 +08:00
    @ClutchBear 上午就是这样做的,没成功,刚才重新写了一下代码,就好了。。。我也无语了,应该是哪边细节写错了,感谢感谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1197 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:12 · PVG 07:12 · LAX 16:12 · JFK 19:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.