2017-02-27 35 views
1

以下時,是我使用我得到一個錯誤「調用的對象已經與其客戶端斷開」自動我的網站

Sub IE_try() 

Application.ScreenUpdating = False 

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 

IE.Navigate "my site" 

Application.StatusBar = "Submitting" 

While IE.Busy 
DoEvents 
Wend 

delay 5 
IE.Document.getElementByClass("ms-textSmall ms-srch-sb-prompt ms-helperText").Value = "abc" 

IE.Documnet.getElementByName("ms-srch-sb-searchImg").Click 

End Sub 

錯誤信息代碼:

謝謝提前:)

回答

0

您遇到了一個奇怪的錯誤。通常你的代碼有點不對 - 你應該使用getElementsByClassname而不是getElementsByClass。這裏有一些開始,爲StackOverflow網站工作,在搜索引擎中編寫abv

Option Explicit 

Sub IE_try() 

    Dim Element  As Object 
    Dim IE   As Object 

    Set IE = CreateObject("InternetExplorer.Application") 
    IE.Visible = True 

    IE.Navigate "http://stackoverflow.com" 

    While IE.Busy 
     DoEvents 
    Wend 

    Set Element = IE.Document.getElementsByClassname("f-input js-search-field") 
    Element.Item.Value = "abv" 

End Sub 
相關問題