2012-06-22 22 views
1

我使用Perl自動化網站WWW::Selenium。 我想知道如何處理點擊上傳或下載按鈕後出現的彈出窗口。如何處理上傳/下載彈出窗口

單擊上傳按鈕時,會打開一個對話窗口來選擇文件。 單擊下載按鈕時,會打開一個對話窗口來選擇要保存文件的位置。

上述場景如何在WWW::Selenium中自動實現?

CODE

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); 
} 
+0

你可以分享你嘗試解決了嗎? – Amey

+0

一般很難處理它們,因爲這不是瀏覽器,而是業務... –

回答

0

上傳情景,可以很容易地通過使用send_keys命令

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