【问题标题】:How to deal with upload/download pop-up window如何处理上传/下载弹窗
【发布时间】:2012-06-22 15:02:52
【问题描述】:

我正在使用 Perl WWW::Selenium 自动化网站。 我想知道如何处理点击上传或下载按钮后弹出的窗口。

单击上传按钮时,会打开一个对话框窗口以选择文件。 单击下载按钮时,将打开一个对话框窗口以选择要保存文件的位置。

上述场景如何在WWW::Selenium中实现自动化?

代码

sub import_files()
{
   # http://mygengo.com/string/p/<proj_name>-1/admin/languages/import/en
   $url = $MYGENGO_STRING_PROJECT_URL . $_[0] . "-1" . $IMPORT_FILES;
   $sel->open($url);

   $sel->attach_file("class=qq-upload-button string-file-import", 
    "http://localhost/1.php"); # But this does not open the file browse window

   $sel->click("class=qq-upload-button string-file-import");
   $sel->wait_for_page_to_load(9000); 
}

【问题讨论】:

  • 一般来说很难处理它们,因为那不是浏览器而是操作系统......

标签: perl selenium


【解决方案1】:

使用send_keys命令可以轻松解决上传场景

driver.find_element_by_xpath("//*[@id='upload-import-link']/input").send_keys(file)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    相关资源
    最近更新 更多