2017-09-18 4 views
0

With seleniumzipファイルをダウンロードしようとしていますが、ダウンロードウィンドウはmany suggestions in this questionにもかかわらずポップアップし続けます。彼らは未知の理由のために働かない。おそらく、ダウンロードリンクがiframeの内部にあるからでしょうか?とにかくFirefoxでセレンのダウンロードダイアログにアクセスするには?

私は作業例を投稿することができない、私はSave to diskボタンとOKボタンをクリックしてセレンをダウンロードポップアップにアクセスする必要がある、またはTOオプションSave link as ...

を選択するために、ダウンロードリンクを右クリックし、問題のWebページは公開されていないためです。クラス定義がプロファイルの設定などを妨害している可能性があります。

ダウンロードダイアログのポップアップダイアログにアクセスする方法はありますか?

関連質問:完全性についてはhere

:ここでは、すべてのプロファイルの設定です:

profile = webdriver.FirefoxProfile() 
profile.set_preference("browser.download.dir", download_dir) 
profile.set_preference("browser.download.folderList", 2) 
profile.set_preference("browser.download.useDownloadDir", True); 
profile.set_preference("browser.download.manager.showWhenStarting", False) 
profile.set_preference("pdfjs.disabled", True) 
profile.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream") 
profile.set_preference("browser.download.manager.alertOnEXEOpen", False); 
profile.set_preference("browser.download.manager.focusWhenStarting", False); 
profile.set_preference("browser.helperApps.alwaysAsk.force", False); 
profile.set_preference("browser.download.manager.alertOnEXEOpen", False); 
profile.set_preference("browser.download.manager.closeWhenDone", True); 
profile.set_preference("browser.download.manager.showAlertOnComplete", False); 
profile.set_preference("browser.download.manager.useWindow", False); 
profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting",False); 
+0

'browser.helperApps.neverAsk.saveToDisk'の設定で、ダウンロードしたファイルのリクエストによって返されるmimeを設定する必要があります。 –

+0

しました。私の質問で提供した完全なプロファイルを確認してください – Alex

+0

正確なMIMEは返信のヘッダーに返されますか?あなたの質問に無関係なMIMEがたくさん含まれているので、明確ではありません。 –

答えて

0

設定が動作しない場合は、私が仕事をするためのAutoItスクリプトを使用:

$result = 1 
$txt = "" 
WinWait($CmdLine[2]) 
WinActivate($CmdLine[2],"") 
WinFlash($CmdLine[2], "", 1, 50) 
If (StringCompare("Opening", $CmdLine[2], 0) = 0) Then ;For FF 
    Send("!s"); 
    Send("{ENTER}") 
    WinWait("Enter name of file to save to…") 
    WinActivate("Enter name of file to save to…","") 
    WinFlash("Enter name of file to save to…", "", 1, 50) 
    $txt = ControlGetText("Enter name of file to save to…", "", "[CLASS:Edit; INSTANCE:1]") 
    If (StringCompare($CmdLine[1], $txt, 0) = 0) Then 
     $result = 0 
    EndIf 
    ControlClick("Enter name of file to save to…", "", "[CLASS:Button; INSTANCE:2]") 
    WinWaitNotActive("Enter name of file to save to…") 
EndIf 

If (StringCompare("Save As", $CmdLine[2], 0) = 0) Then ; For Chrome 
    $txt = ControlGetText($CmdLine[2], "", "[CLASS:Edit; INSTANCE:1]") 
    If (StringCompare($CmdLine[1], $txt, 0) = 0) Then 
     $result = 0 
    EndIf 
    ControlClick($CmdLine[2], "", "[CLASS:Button; INSTANCE:2]") 
    WinWaitNotActive($CmdLine[2]) 
EndIf 
Exit $txt 

または次のautoItスクリプト:

#include <file.au3> 

_Log("----new session----") 

if $CmdLine[0] <> 3 then 
; Arguments are not enough 
msgbox(0,"Error","Supply all the Arguments, Browser name and path to upload") 
_Log("Arguments are wrong") 
Exit 
EndIf 

;Activate firefox/IE browser 
If (StringCompare($CmdLine[1],"firefox",0) = 0) Then 
    $waitTime=$CmdLine[3] 
    if (WinWait("[Class:MozillaDialogClass]","",$waitTime)==0) Then 
     _Log("Window Not Found From FireFox") 
    Else 
    _Log("Waiting For Download Window From FireFox") 
    _FFDownload() 
    EndIf 

ElseIf (StringCompare($CmdLine[1],"ie",0) = 0) Then 
    WinWait("File Download - Security Warning") 
    _Log("Waiting For Download Window From IE") 
    _IEDownload() 
Else 
    Exit 
EndIf 
;Used For IE and Tested on IE6 
Func _IEDownload() 

    $hResult = WinActivate("File Download - Security Warning") 
    If($hResult == 0) Then 
     _Log("Unable to find Download Window from IE") 
    Else 
     $IETitle=WinGetTitle("File Download - Security Warning") 
     _Log("Download Window activated"&$IETitle) 
     WinActivate($IETitle) 
     ControlClick($IETitle, "","[CLASS:Button; INSTANCE:2]") 
     _Log("FileChooser Window opend") 
     _Log("CommandLine Parameter Found and Value is:"&$CmdLine[2]) 
     WinActivate("Save As") 
     _Log("FileChooser Window opend"&WinGetTitle("Save As")) 
     ControlSetText(WinGetTitle("Save As"),"","Edit1",$CmdLine[2]) 
     Send("!s") 
    EndIf 
EndFunc 

;Used for FireFox Browser 
Func _FFDownload() 
    $hResult = WinActivate("[Class:MozillaDialogClass]"); 

    If($hResult == 0) Then 
     _Log("Unable to find Download Window From FireFox") 
    Else 
     ; If firefox is set the save the file on some specif location without asking to user. 
     ; It will be save after this point. 
     ;If not A new Dialog will appear prompting for Path to save 
     _Log("Download Window activated") 
     ;To change the focus on save button 
     Send("{TAB}") 
     Sleep(400) 
     Send("{TAB}") 
     _Log("Change Focus to Save Button") 
     ;This is use for if dialoguebox have save and openwith option 
     Send("!s") 
     ;Click on Enter to Save 
     Sleep(400) 
     Send("{ENTER}") 
     _Log("Press Enter") 
     Sleep(400) 

     If(WinExists(WinGetTitle("[ACTIVE]"))) Then 
      WinActivate("Enter name of file to save to…") 
      $title = WinGetTitle("[ACTIVE]") 
      if($title=="Enter name of file to save to…")Then 
      _Log("Active Window Title Is:"&WinGetTitle("[ACTIVE]")) 
      _Log("EnterName Window Opened And Tiltle is:"&$title) 
      ;ControlSetText($title,"","Edit1",$CmdLine[2]) 
      ControlFocus($title, "", "Edit1") 
      Send($CmdLine[2]) 
      Sleep(3000) 
      ; Save File 
      _Log("CommandLine Parameter Found For FilePath and Value is:"&$CmdLine[2]) 
      ;Send("!s") 
      ;Sleep(3000) 
      ControlClick("[CLASS:#32770]", "", "Button1") 
      EndIf 
     EndIf 

    EndIf 
EndFunc 
;used for logging 
Func _Log($sLogMsg) 
_FileWriteLog(@ScriptDir & "\AutoItLog.log",$sLogMsg) 
EndFunc 
関連する問題