保存对话框无法进行Interact - Selenium Webdriver with Java

时间:2014-01-29 07:17:53

标签: selenium selenium-webdriver autoit

之前,我是这个AutoIT的新手,我不熟悉这个,只是谷歌并需要完成我的任务,如果我的AtotoIt有任何错误请更正

范围: 在从IE(版本9)下载Xml期间,它将打开“你想打开还是保存对话框”,所以我想点击保存按钮将该xml文件保存在默认的临时文件夹中 enter image description here

我的autoIT代码(来自http://qtp-help.blogspot.in/2009/07/selenium-handle-dialogs.html#handle_save_dialog的参考)

AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to select using substring

if $CmdLine[0] < 2 then
; Arguments are not enough
msgbox(0,"Error","Supply all the arguments, Dialog title,Run/Save/Cancel and Path to     save(optional)")
Exit
EndIf

; wait Until dialog box appears
WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
WinActivate($title)

If (StringCompare($CmdLine[2],"Open",0) = 0) Then
WinActivate($title)
ControlClick($title,"","Button1")
EndIf

If (StringCompare($CmdLine[2],"Save",0) = 0) Then
WinWaitActive($title)
ControlClick($title,"","Button2")
; Wait for the new dialogbox to open
EndIf

If (StringCompare($CmdLine[2],"Cancel",0) = 0) Then
WinWaitActive($title)
ControlClick($title,"","Button3")
EndIf

我的java代码

WebElement downloadLink = driver.findElement(By
            .xpath("(//img[@alt='Download'])[3]"));
    downloadLink.click();
    Thread.sleep(4000);
    dialog = new String[] {
            "C:\\Users\\Prabakar\\Desktop\\Save_Dialog_IE.exe", "Save" };
    Runtime.getRuntime().exec(dialog);

请帮忙解决

2 个答案:

答案 0 :(得分:0)

在不使用AutoIT的情况下,查看下载文件的其他方法。

How to make browser closed after completing download?

答案 1 :(得分:0)

#include <_XMLDomWrapper.au3>
#include <File.au3>

Global $oXML = ObjCreate("Microsoft.XMLHTTP")
$oXML.Open("GET", "YOUR URL LIKE: http://www.google.com", 0)
$oXML.Send

Global $sFile = _TempFile(@TempDir, '~', '.xml')
FileWrite($sFile, $oXML.responseText)

这对你有用吗?您可以从HERE

获取XMLDomWrapper.au3

Source