返回列表 上一主題 發帖

[發問] 執行階段錯誤 '438': 物件不支援此屬性或方法

[發問] 執行階段錯誤 '438': 物件不支援此屬性或方法

本帖最後由 av8d 於 2014-8-18 13:54 編輯

登入用.rar (21.05 KB)
  1. Private Sub CommandButton3_Click()
  2. '帳密驗證
  3.     With CreateObject("InternetExplorer.Application")
  4.         .Navigate "https://cas.tycg.gov.tw/casserver/login?service=http%3A%2F%2Fe.tycg.gov.tw%2Fapp%2Fportal%2Flogin"
  5.    
  6.         Do While .Busy Or .ReadyState <> 4
  7.             DoEvents
  8.         Loop
  9.         
  10.         '帳號欄位
  11.         .Document.all("username").innerText = "A"
  12.         '密碼欄位
  13.         .Document.all("password").innerText = "B"
  14.         .Document.all("usernamebutton").Click
  15.         .Visible = True
  16.         '.Navigate "http://odis.tycg.gov.tw/HOME/Home_Splitter.aspx"
  17.     End With
  18. End Sub
複製代碼
帳號成功自動丟上去,到了密碼就卡住了,懇請大大們幫忙,謝謝
我會繼續在網路上尋找解答!

回復 1# av8d
網頁在桃園縣政府民政局內部嗎?無法連上線,
你可查看這登入網頁的原始碼,可參考這裡
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 2# GBKEE

原始檔.rar (2.73 KB)

TOP

回復 3# av8d
  1. Option Explicit
  2. Dim FormDLL As String
  3. Sub Ie_document()
  4.     Dim URL As String, Ie As Object, A As Object, i
  5.    ' URL = "D:\原始檔.htm"
  6.     URL = "https://cas.tycg.gov.tw/casserver/login?service=http%3A%2F%2Fe.tycg.gov.tw%2Fapp%2Fportal%2Flogin"
  7.     Set Ie = CreateObject("InternetExplorer.Application")
  8.     With Ie
  9.         .Navigate URL
  10.         .Visible = True
  11.         Do While .Busy Or .readyState <> 4:         Loop
  12.         Stop   '網頁上輸入 帳號,密碼 後繼續程式
  13.         On Error Resume Next
  14.         Set A = .document.ALL
  15.         For i = 0 To A.Length - 1
  16.             Cells(i + 1, "A") = A(i).TAGNAME
  17.             Cells(i + 1, "B") = A(i).ID
  18.             Cells(i + 1, "C") = A(i).Name
  19.             Cells(i + 1, "D") = A(i).Value
  20.             Cells(i + 1, "E") = A(i).INNERTEXT
  21.             Cells(i + 1, "F") = A(i).Type
  22.         Next
  23.         '到工作表上看 [帳號,密碼]在哪一個元素上
  24.     End With
  25. End Sub
  26. Sub Ie()
  27.     Dim URL As String, Ie As Object, i
  28.     'URL = "D:\原始檔.htm"
  29.     URL = "https://cas.tycg.gov.tw/casserver/login?service=http%3A%2F%2Fe.tycg.gov.tw%2Fapp%2Fportal%2Flogin"
  30.    
  31.     Set Ie = CreateObject("InternetExplorer.Application")
  32.     With Ie
  33.         .Navigate URL
  34.         .Visible = True
  35.         Do While .Busy Or .readyState <> 4:         Loop
  36.         With .document.getElementsByTagName("input")
  37.             .Item("pincode").Value = "pincode"
  38.             .Item("pinpassword").Value = "pinpassword"
  39.             
  40.             '****************
  41.             .Item("username").Value = "帳AAA號"
  42.             For i = 0 To .Length - 1
  43.                 If .Item(i).ID = "password" And .Item(i).Name = "password" Then
  44.                                  '大小寫有分別
  45.                    .Item(i).Value = "TEST"
  46.                 End If
  47.             Next
  48.             '********************
  49.             .Item("pinbutton").Click  '這裡我無法測試
  50.         End With
  51.     End With
  52.    
  53. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 av8d 於 2014-8-18 21:42 編輯

回復 4# GBKEE


請問
帳號是填在  帳AAA號
密碼是填在  TEST 上  這樣?
是不是因為他是用ASP寫的~所以會比較複雜?
再次感謝版主用心良苦的幫助.

Sub Ie_document()
Sub Ie()
是選擇一個即可?

TOP

本帖最後由 GBKEE 於 2014-8-19 08:12 編輯

回復 5# av8d
帳號是填在  帳AAA號
密碼是填在  TEST 上  這樣?
是不是因為他是用ASP寫的~所以會比較複雜?
Sub Ie_document()
Sub Ie()
是選擇一個即可?

是帳號填上   "帳AAA號"
是密碼填上   'TEST"
是不是因為他是用ASP寫的~所以會比較複雜? ,應該不是
Sub Ie_document() 程式讓你明暸網頁上要輸入元素,的TAGNAME, ID, NAME, VALUE ,INNERTEXT,好對號入座
Sub Ie() 執行你要的動作
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 av8d 於 2014-8-19 10:56 編輯

回復 6# GBKEE


    非常感謝板大解開難題~我稍做修改了一下~還是感覺不是很通順~因為複製貼上的關係出現了兩個With~
  1. Private Sub CommandButton1_Click()
  2. '帳密驗證
  3.     With CreateObject("InternetExplorer.Application")
  4.         .Navigate "https://cas.tycg.gov.tw/casserver/login?service=http%3A%2F%2Fe.tycg.gov.tw%2Fapp%2Fportal%2Flogin"
  5.    
  6.         Do While .Busy Or .ReadyState <> 4
  7.             DoEvents
  8.         Loop
  9.         
  10.         .Visible = True
  11.         '帳號欄位
  12.         .Document.all("username").innerText = "***"
  13.         '密碼欄位
  14.         '.Document.all("password").innerText = "***"
  15.     With .Document.getElementsByTagName("input")
  16.         For i = 0 To .Length - 1
  17.             If .Item(i).ID = "password" And .Item(i).Name = "password" Then
  18.                              '大小寫有分別
  19.                .Item(i).Value = "***"
  20.             End If
  21.         Next
  22.     End With
  23.         .Document.all("usernamebutton").Click
  24.     End With
  25. End Sub
複製代碼
新提問
如果重複執行,會出現
執行階段錯誤'91'
沒有設定物件變數或 With 區塊變數
錯誤段落如下
.Document.all("username").innerText = "***"
我在想應該是重複登入,因此找不到帳號欄位
所以我使用了On Error Resume Next,請問版主是否可行

TOP

本帖最後由 GBKEE 於 2014-8-19 11:10 編輯

回復 7# av8d
  1. .Document.all("username").innerText = "***"
複製代碼
這語法是錯誤的應如下
  1. .Document.all("username").VALUE ="***"
複製代碼
必須是已登出,才有登入的網頁可用,何謂重複登入??
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 av8d 於 2014-8-19 14:25 編輯

回復 8# GBKEE


    可能是已經登入了~但是在按一次~他會找不到輸入帳號和密碼的地方,
他會直接前往帳號密碼正確的頁面,所以他會出現找不到帳號欄位的錯誤,
因此我使用忽略On Error Resume Next解決可否?謝謝版主!

TOP

回復 8# GBKEE


    請問版主如果會跳出網頁訊息,我該如何自動關閉呢?

TOP

        靜思自在 : 甘願做、歡喜受。
返回列表 上一主題