【问题标题】:Sending data to a Window with AutoIt Python使用 AutoIt Python 将数据发送到窗口
【发布时间】:2016-09-09 09:37:30
【问题描述】:

我正在使用 Selenium 和 AutoIT 将图像上传到站点。 现在我需要从 Firefox 的“文件上传”窗口中选择一个文件,然后单击 Enter。 所以这是代码的 AutoIT 部分:

driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div/div/ul[1]/li/button").click()
    autoit.win_wait_active("File Upload", 5)
    autoit.send(os.path.join(mpath,"1.jpg"))
    autoit.send("{ENTER}")

这个脚本运行良好 现在的问题是窗口需要在我的计算机上处​​于活动状态才能上传文件,因此在脚本运行时我无法做任何其他工作。 如何在不激活窗口的情况下发送相同的数据?

【问题讨论】:

  • 你试过机器人方法吗?
  • Selenium 支持文件上传,无需使用 AutoIt。
  • @Florent B. 我认为 Selenium 不支持通过窗口上传文件。我的意思是,就我阅读文档而言,我无法选择带有 Selenium 的 Firefox 上传窗口。
  • @KishanPatel 什么是机器人方法?对不起,我对 python 有点陌生。
  • @user2726634,是的,您可以通过 element.sendKeys("full file path") 使用 Selenium 上传文件。请注意,该元素必须是 <input> 而不是按钮。它已记录在案,我也可能多次测试过。

标签: python selenium selenium-webdriver autoit


【解决方案1】:

改用这个:

    autoit.win_wait("[CLASS:#32770;TITLE:Open]", 60)
    autoit.control_send("[CLASS:#32770;TITLE:Open]", "Edit1", os.path.join(mpath,"1.jpg"))
    autoit.control_click("[CLASS:#32770;TITLE:Open]", "Button1")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 2013-10-06
    • 2011-10-06
    相关资源
    最近更新 更多