AutoIt Firefox _FFClick 在按钮上不起作用? (FF.au3)
AutoIt Firefox _FFClick doesn't work on button? (FF.au3)
使用 firefox 插件 ("ff-au3") for AutoIt, 如何单击按钮?
这是我要点击的项目的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(Firefox 插件)
- MozRepl v.1.1.2
- SciTE-Lite 3.5.4 版
好吧,这并没有带来多少流量,但我找到了解决方案!很简单...我在执行点击之前断开了与 firefox 的连接!
使用firefox时,首先需要使用"Run"命令打开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