AutoIt Firefox _FFClick无法处理按钮? (FF.au3)

时间:2016-02-09 01:47:01

标签: autoit mozrepl

使用 firefox 插件(" ff-au3 ")进行 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

任何人都会看到我做错了什么?

版本:

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

1 个答案:

答案 0 :(得分:2)

嗯,这没有太多的流量,但我找到了解决方案!非常简单......在执行点击之前我与firefox断开连接!

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

工作解决方案: myScript.au3 (请参阅底部的“登录”功能)

#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