【问题标题】:Upload File using selenium on Pyhon (IE only)在 Python 上使用 selenium 上传文件(仅限 IE)
【发布时间】:2018-11-13 08:44:11
【问题描述】:

我正在使用下面的代码使用 selenium 驱动 Microsoft IE 上传文件。 但我无法将_keys 发送到文件输入。然而,下面的代码打开了浏览文件窗口(这只发生在 IE 中,而不是 firefox)

有没有办法使用仅 IE,我可以将_keys 发送到 html 输入,或者在最坏的情况下,我可以将_keys 发送到弹出浏览窗口,然后单击打开? p>

html代码:

<TR>
<TD class="label">File Name:</TD>
<TD id="tagFile"><INPUT size=30 TYPE="file" NAME="fileName"></TD>
</TR>   
<TR>

html截图:

浏览截图:

代码:

driver.find_element_by_css_selector("img[alt=\"Add Document\"]").click()
driver.find_element_by_name("title").send_keys("PCA Documentation")
driver.find_element_by_name("issueNo").send_keys("1")
print destination

file_input = driver.find_element_by_name("fileName")    
#driver.file_input.send_keys(destination)   
driver.file_input.send_keys("C:\\installAgent.log")                                     
driver.find_element_by_css_selector("img[alt=\"Upload my file\"]").click()

【问题讨论】:

  • 不应该只是file_input.send_keys("C:\\installAgent.log")而不是driver.file_input.send_keys("C:\\installAgent.log")吗?
  • 我最终想通了并使用了 driver.find_element_by_name("fileName").send_keys(destination)
  • 这可以是答案,请提交您的答案

标签: python selenium file-upload upload


【解决方案1】:

应该只是file_input.send_keys("C:\\installAgent.log") 而不是driver.file_input.send_keys("C:\\installAgent.log")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-08
    • 2012-01-15
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多