1

使用AutoIt的firefox插件(“ ff-au3 ”),如何单击按钮

这是我要单击的项目的 HTML:

<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">

这是单击按钮的代码片段:

   ;Click the "Log In" button, id is "login-form-submit"
   _FFClick("login-form-submit", "id")

此时,我的脚本已经连接到 firefox,已经在我需要的页面上,其他一切正常(除了这个点击部分!)

这是我回来的错误:

_FFClick ==> No match: $sElement: FFau3.WCD.getElementById('login-form-submit')

此外,当我使用 javascript 控制台在页面上手动运行它时,这也有效:

document.getElementById("login-form-submit")

这是插件的 API: http: //english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFClick.php

有人看到我做错了什么吗?

版本:

  • 火狐 44.0.1
  • AutoIt v3.3.14.2
  • FF V0.6.0.1b-15.au3(火狐插件)
  • MozRepl v.1.1.2
  • SciTE-Lite v. 3.5.4
4

1 回答 1

2

好吧,这并没有带来太多流量,但我找到了解决方案!很简单......我在执行点击之前断开了与firefox的连接!

使用firefox时,首先需要使用“运行”命令打开firefox exe,然后需要使用“_FFConnect”命令连接firefox。接下来,您可以开始单击元素。完成后,使用“ProcessClose”命令断开与 Firefox 的连接。我遇到的问题是我连接到Firefox,然后立即断开连接,然后我尝试点击。因此,我确保在单击后断开连接...

工作解决方案:myScript.au3(参见底部的“LogIn”功能)

#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <EventLog.au3>
#include <FF V0.6.0.1b-15.au3> ;FireFox

OpenLog()
OpenFirefox()
ConnectToFirefox()
LogIn()

; ////////////////////////////////////////////////////
; Configure the Log
; ////////////////////////////////////////////////////
Func OpenLog()

   Global $log = FileOpen("K:\Log.txt", 2)

   ; Check if file opened for reading OK
   If $log == -1 Then
       FileWrite($log,"[ERROR] Could not open log file." & @CRLF)
       MsgBox(0, "Error", "Unable to open log file.", [ timeout = 0])
       Exit
    Else
       FileWrite($log,"[INFO] Opened log file successfully." & @CRLF)
    EndIf

EndFunc

; ////////////////////////////////////////////////////
; Open Firefox
; ////////////////////////////////////////////////////
Func OpenFirefox()
   ;Run Firefox in Maximized
   Global $ffPid = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe","",@SW_MAXIMIZE)

   ; Check if firefox was opened OK
   If @error <> 0 Then
       FileWrite($log,"[ERROR] Could not open firefox." & @CRLF)
       MsgBox(0, "Error", "Could not open firefox.", [ timeout = 0])
       Exit
    Else
       FileWrite($log,"[INFO] Firefox opened successfully." & @CRLF)
    EndIf

   ;Wait 10 seconds for Firefox to open
   $result = WinWait("[CLASS:MozillaWindowClass]","",10)

   ; Check if file opened for reading OK
   If $result == 0 Then
       FileWrite($log,"[ERROR] Unable to open firefox class." & @CRLF)
       MsgBox(0, "Error", "Unable to open firefox class.", [ timeout = 0])
       Exit
    Else
       FileWrite($log,"[INFO] Opened firefox class successfully." & @CRLF)
    EndIf

   ;Wait for 2 seconds after opening
   Sleep(2000)

EndFunc

; ////////////////////////////////////////////////////
; Connect To Firefox
; ////////////////////////////////////////////////////
Func ConnectToFirefox()
   ; trying to connect to a running FireFox with MozRepl on
   If _FFConnect(Default, Default, 3000) Then
       FileWrite($log,"[INFO] Connected to Firefox." & @CRLF)
   Else
       FileWrite($log,"[ERROR] Can't connect to FireFox!" & @CRLF)
       MsgBox(64, "", "Can't connect to FireFox!")
   EndIf

   ;Wait for 2 seconds after opening
   Sleep(2000)
EndFunc

; ////////////////////////////////////////////////////
; Log into page
; ////////////////////////////////////////////////////
Func LogIn()
   ;Load Login Page
    _FFOpenURL("http://localhost/login.jsp")
    Sleep(2000)
    If @error <> 0 Then
       FileWrite($log,"[ERROR] Could not open URL." & @CRLF)
       MsgBox(0, "Error", "Could not open URL.", [ timeout = 0])
       Exit
    Else
       FileWrite($log,"[INFO] Opened URL successfully." & @CRLF)
    EndIf


   Sleep(2000)
   ;Click the "Log In" button, id is "login-form-submit"
   ;<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
   _FFClick("login-form-submit", "id")

   If @error <> 0 Then
       FileWrite($log,"[ERROR] Could not click login button." & @CRLF)
       MsgBox(0, "Error", "Could not click login button:", [ timeout = 0])
       Exit
    Else
       FileWrite($log,"[INFO] Found and clicked login button successfully." & @CRLF)
    EndIf
EndFunc
于 2016-02-09T18:42:41.600 回答