【发布时间】:2016-02-26 09:44:22
【问题描述】:
我需要自动上传文件。
这是一个HTML 用于文件路径输入字段和手动上传按钮的代码:
<div class="ctrl_div">
<input id="fileupload" class="hid" name="files" accept="application/zip" data-url="/Server/file/upload" type="file">
<button id="fileBtn" class="btn btn-primary" type="button">Upload</button>
</div>
当我尝试时
driver.find_element_by_xpath('//input[@id="fileupload"]').send_keys(path_to_file)
我收到ElementNotVisibleException
我也试过了
driver.execute_script("document.getElementById('fileupload').style.visibility = 'visible';")
但webdriver 的输入字段仍然不可见。
有什么想法吗?
附:添加隐式/显式等待不会产生任何影响
【问题讨论】:
-
如果你想点击浏览按钮使用这个xpath:.//*[@id='fileupload']上传按钮xpath是:.//*[@id='fileBtn']
-
你的 HTML DOM 上是否还有其他与
-
你应该试试
driver.execute_script(document.getElementById('fileUpload').style.display='block';"); -
@sameerjoshi,没有。按钮不是目标元素
-
@fabersky ,是的,它似乎有效。谢谢。您可以删除您的评论并将其作为答案提供,以便我接受它
标签: python selenium selenium-webdriver