2017-06-07 101 views
1

我是JavaScript和autohotkey programmation的新手。我正在嘗試登錄網站,但到目前爲止我無法正確提交表單。JavaScript:使用autohotkey登錄網站

這裏是頁面的HTML:

 <form ng-show="!maintenanceCritique" class="form ng-pristine ng-valid-pattern ng-valid-maxlength ng-valid ng-valid-required" name="formMobile" ng-submit="login(formMobile)" novalidate="" touch-submit=""> 
 

 

 
      <div style="padding-top:30px;padding-left:20px;padding-right:20px"> 
 

 
        <span>&nbsp;&nbsp;Code permanent</span><br> 
 
        <input style="width:100%" name="codePermanent" ng-model="user.codePermanent" ng-pattern="/^[A-Za-z]{4}(0[1-9]|[12][0-9]|3[01]|6[3-9]|[78][0-9]|9[0-3]|99)([0,5][1-9]|[1,6][012]|13|63)[0-9]{4}$/" maxlength="12" tabindex="1" placeholder="(ex. : ABDC12034566)" autofocus="" required="" class="ng-pristine ng-valid-pattern ng-valid-maxlength ng-not-empty ng-valid ng-valid-required ng-touched"> 
 

 
        <br><br> 
 
        <span>&nbsp;&nbsp;NIP</span><br> 
 
        <input style="width:100%" type="password" name="password" ng-model="user.password" ng-pattern="/^[0-9]{5}$/" maxlength="5" tabindex="2" placeholder="(ex. : 12345)" required="" class="ng-pristine ng-valid-pattern ng-valid-maxlength ng-not-empty ng-valid ng-valid-required ng-touched"> 
 

 
        <div> 
 
        <!-- ngIf: formMobile.codePermanent.$error.required && formMobile.password.$error.required && submitted --> 
 
        <!-- ngIf: err --> 
 
        </div> 
 
        <br> 
 

 
        <div style="text-align:right"> 
 
         <button class="btn btn-default btn-inverse btn-lg btn-login text-uppercase" type="submit" click="submitted=true" tabindex="3"> 
 
         <span style="height:60%;width:140px;text-transform:none;font-family:'Conv_Dosis',arial,sans-serif; font-size:100%">Connexion</span> 
 
        </button> 
 
        </div> 
 
    </form> 
 
    </div>

這裏是我的代碼:

WB := ComObjCreate("InternetExplorer.Application") 
WB.Visible := True 
WB.Navigate(URL) 

loop 
If !WB.busy 
break 
sleep 1000 


WB.document.getElementsByName("codePermanent")[0].focus() 
WB.document.getElementsByName("codePermanent")[0].value := "username" 
sleep 1000 
WB.document.getElementsByName("password")[0].focus() 
WB.document.getElementsByName("password")[0].value := "password" 

form := WB.document.getElementsByName("form")[0] 
form.method := "post" 
form.submit() 

回答

0

你可以試試這個:

wb.document.getElementsByClassName("btn btn-default btn-inverse btn-lg btn-login text-uppercase")[0].click() 

如果該按鈕是頁面中第一個具有該類名稱的按鈕,將會點擊提交按鈕。 Remeber,getElementsByClassName()返回一個nodelist,所以你必須指定你想要點擊的特定元素,方法是在方括號中包含它的引用。

從那裏,這只是使用.click()方法的問題。

如果這回答你的問題,請標記回答的問題。 如果沒有,讓我知道,所以我們可以得到它的答案。

+0

我已經嘗試過了,並沒有記錄我,可惜你 –

+0

可以嘗試通過passint通過jQuery點擊它,它通過地址欄。看看它是否有效:'wb.Navigate(JavaScript:$('input [type = submit]')。click())' – GroggyOtter

0

你的問題是,你永遠不會得到窗體元素。您試圖通過其標記名稱來訪問它,但是您正在使用getElementsByName方法。相反,你應該使用的getElementsByTagName方法:

WB := ComObjCreate("InternetExplorer.Application") 
WB.Visible := True 
WB.Navigate(URL) 

While WB.readyState!=4 || WB.document.readyState!="complete" || WB.busy 
    Sleep 50 

WB.document.getElementsByName("codePermanent")[0].value := "username" 
WB.document.getElementsByName("password")[0].value := "password" 
Sleep 1000 
form := WB.document.getElementsByTagName("form")[0] ; TagName - not Name 
form.method := "post" 
form.submit()