代码之家  ›  专栏  ›  技术社区  ›  Ossama

在pyhon上使用selenium上载文件(仅限于ie)

  •  -1
  • Ossama  · 技术社区  · 6 年前

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

    有没有办法用 只有IE ,在那里我可以向HTML输入发送_键,或者在最坏的情况下,我可以向弹出的浏览窗口发送_键,然后单击“打开”?

    HTML代码:

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

    HTML屏幕截图:

    enter image description here

    浏览屏幕截图:

    enter image description here

    代码:

    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()
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   GPT14    6 年前

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