【问题标题】:How to send text to invisible input field如何将文本发送到不可见的输入字段
【发布时间】: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


【解决方案1】:

你应该试试

driver.execute_script(document.getElementById('fileUpload').style.display='bloc‌​k';");

【讨论】:

    猜你喜欢
    • 2021-02-25
    • 1970-01-01
    • 2011-10-27
    • 2021-06-11
    • 2023-03-16
    • 2017-08-14
    • 1970-01-01
    • 2017-03-29
    • 2016-12-31
    相关资源
    最近更新 更多