【问题标题】:Save dialog not able to Interact - Selenium Webdriver with Java保存对话框无法交互 - Selenium Webdriver 与 Java
【发布时间】:2014-01-29 07:17:52
【问题描述】:

之前,我是这个AutoIT的新手,对此我不熟悉,只是google,需要完成我的任务,如果我的AtotoIt有任何错误,请纠正它

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

我的 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);

请帮忙解决

【问题讨论】:

    标签: selenium selenium-webdriver autoit


    【解决方案1】:

    看看其他不使用 AutoIT 下载文件的方法。

    How to make browser closed after completing download?

    【讨论】:

      【解决方案2】:
      #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)
      

      这对你有用吗? XMLDomWrapper.au3 可以从HERE获得

      Source

      【讨论】:

        猜你喜欢
        • 2017-08-14
        • 2016-10-07
        • 1970-01-01
        • 2012-12-24
        • 1970-01-01
        • 1970-01-01
        • 2015-08-29
        • 2018-07-08
        • 1970-01-01
        相关资源
        最近更新 更多