【问题标题】:Canot click button with Python with Selenium无法使用带有 Selenium 的 Python 单击按钮
【发布时间】:2015-09-26 13:12:31
【问题描述】:

我正在尝试单击一个按钮,该按钮会弹出一个对话框来选择文件。检查它看起来像是输入而不是按钮的元素。无论哪种方式,我都无法点击它:

element = browser.find_element_by_id("fileupload")
element.click()

browser.find_element_by_id("fileupload").send_keys("\n")

这两种方法似乎都不起作用。

这是我在页面上检查该元素时看到的内容:

<span class="btn btn-success fileinput-button">
  <span class="glyphicon glyphicon-upload"></span> 
    Select and Upload...
  <input id="fileupload" name="upfile" accept=".xml" type="file">
</span>

任何帮助或指点将不胜感激!

【问题讨论】:

    标签: python html selenium input selenium-webdriver


    【解决方案1】:

    单击文件输入通常会触发文件上传对话框。由于您无法使用selenium 控制它,因此您需要通过将密钥发送到input 来避免打开对话框:

    browser.find_element_by_id("fileupload").send_keys("path_to_the_file")
    

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多