2016-07-05 3 views
0

IE.document.getElementbyIDを使用してIEの検索ボックスにテキストを読み込む際に問題があります。これまで使用していたコードを含めています。私はここで何かを逃していると確信しています。これは、あなたがキャッチしようとしているオブジェクトが"data-automation-id"属性を持つ、ID属性を持っていない私はここに実行時エラー '424':Object Required IE.Document.GetElementById iframe内のテキストボックス

<iframe tabindex="-1" id="WorkdayApp" src="javascript:""" style="left: -1000px; top: -1000px; width: 0px; height: 0px; border-top-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; position: absolute;"> 

<input class="gwt-TextBox GPNS02MDDGJ" aria-label="Expanded, multiSelectPrompt, 0 items selected, Use up and down arrows to select. or Type in a search" type="text" placeholder="search" data-automation-id="searchBox"/> 

含めていますインラインフレームコード」

Sub workdayrep() 

'******************************* 
Dim iframe As Object 
Dim textbox As Object 
'******************************* 
Dim IE As InternetExplorer 
Set IE = New InternetExplorer 
Set iframe = IE.document.getElementById("WorkdayApp") 
Set textbox = iframe.contentWindow.document.getElementById("searchBox") 
IE.Visible = True 


IE.navigate "https://wd.workday.com/142.htmld" 

Application.StatusBar = "Page Loading" 

'Do While IE.Busy 
' Application.Wait DateAdd("s", 1, Now) 
' Loop 
Application.Wait Now + TimeValue("00:00:10") 
textbox.Value = "TEST" 

' Application.StatusBar = "Check" 
End Sub 
+1

私はそれをテストすることはできませんが、私はまだIE.BusyそれともIE.ReadyState <ながらあなたは '使用することをお勧め> 4:DoEvents関数:Wend'代わりに'アプリケーションの。 Wait' ...また、IE.document.getElementById( "searchBox") 'はただ1つのオブジェクトを返しますか?ただの 'stop'か、ブレークポイントを経由して、あなたの' getElementById'前に、あなたのコードを停止し、あなたの ''直接IE.document.getElementById(「検索ボックス」)、「時計」に入れて、それが返されないかどうか確認...私は単純にしないでくださいあなたが '.Value'を介して直接アクセスできると思います –

+0

私はちょうど私がテキストを入力しようとしているサイトのコードを見ていますそれはiframe内

+0

時にはIEの自動化VBAで少し奇妙なことができます。 Value = SV'それを試してみると、私はあなたの検索値を文字列 'Dim SV as String'' SV =" TEST "'で直接定義してみることができます。私の最近のウェブスクレイピングプロジェクトでこれをたくさんしなければならなかった。 –

答えて

1

の更新です。

そのID、そこに明らかにして他のいくつかの要素がある場合を除きこのよう
<input class="gwt-TextBox GPNS02MDDGJ" aria-label="Expanded, multiSelectPrompt, 0 items selected, Use up and down arrows to select. or Type in a search" type="text" placeholder="search" data-automation-id="searchBox"/> 

getElementByIDは常に(Nothingを返します。この場合はそうではありません!)。 getElementsByClassName("gwt-TextBox GPNS02MDDGJ")を超えるブルートフォースループが必要です。この(未テスト)のようなもの:

Dim itm 
For each itm in iFrame.contentWindow.document.getElementsByClassName("gwt-TextBox GPNS02MDDGJ") 
    If itm.getAttribute("data-automation-id", 2) = "searchBox" Then 
     itm.setAttribte("data-automation-id", "test") 
     Exit For 
    End If 
Next 
+0

しかし、私はElementsByClassNameを使ってみましたが、これは実行時エラー438「オブジェクトはこのプロパティまたはメソッドをサポートしていません」と返されます。 –

+0

そのメソッドをサポートしていないIEの古いバージョンのための[この](http://stackoverflow.com/questions/7410949/javascript-document-getelementsbyclassname-compatibility-with-ie)の可能な回避策を参照してください。 –

+0

も参照[この類似回答](http://stackoverflow.com/questions/23476502/getelementsbyclassname-open-ie-vs-msxml2-methods)(私の)を実装するのが容易であってもよいです。 –

関連する問題