[英]AutoIt Firefox _FFClick doesn't work on button? (FF.au3)
使用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
有人看到我做錯了嗎?
版本:
好吧,這並沒有帶來太多流量,但是我找到了解決方案! 非常簡單...在執行點擊之前,我已從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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.