質問内容
- PowershellでIE操作を行おうとしていますが、下記のようなエラーが発生します。
原因と解決策がわからないのですが、お力添えいただきたいです。
処理
- ログイン画面を開きます
- IDとpasswordを入力し、ログインボタンを押下します。→top画面に遷移
- top画面でリンクを押下します。→一覧画面に遷移
- 一覧画面でも何らかの処理をしたいですが、getElementByIdでエラーが出る
という状況です。
※getElementsByTagName("table")とかでもエラーが出ます。
ソースコード
PowerShell
1class hoge 2{ 3 $Shell 4 $Ie 5 $Doc 6 7 hoge() 8 { 9 # シェルを取得(必要か不明) 10 $this.Shell = New-Object -ComObject Shell.Application 11 12 # IEで開く 13 $this.Ie = New-Object -ComObject InternetExplorer.Application 14 $this.Ie.Navigate([Const]::Url) 15 $this.Ie.Visible = $True 16 17 # 画面切り替え待ち 18 while($this.Ie.Busy) { Start-Sleep -milliseconds 100 } 19 20 #ドキュメントオブジェクト作成 21 $this.Doc = $this.Ie.Document 22 } 23 24 # ログイン画面 25 Login($userId, $password) 26 { 27 $this.Doc.getElementById("name").value = $userId; 28 $this.Doc.getElementById("password").value = $password; 29 $this.Doc.getElementById("login-btn").click(); 30 while($this.Ie.Busy) { Start-Sleep -milliseconds 100 } 31 } 32 33 # Top画面 34 Top() 35 { 36 $this.Doc.Links | ForEach-Object -Process {if($_.innerText -eq "hoge"){$_.click()}} 37 while($this.Ie.Busy) { Start-Sleep -milliseconds 100 } 38 } 39 40 # 一覧画面 41 DateList() 42 { 43 # ここでエラーが発生 44 $this.Doc.getElementById("db_SEARCH_DATE").value 45 } 46} 47 48$hoge = New-Object hoge; 49$hoge.Top(); 50$hoge.DateList()
エラー
HRESULT からの例外:0x800A01B6 発生場所 行:1 文字:1 + $this.Doc.getElementById("db_SEARCH_DATE").value + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], NotSupportedException + FullyQualifiedErrorId : System.NotSupportedException
環境情報
PowerShell 5.1
IE 11
よろしくお願いいたします。
$this.Doc.getElementById("db_SEARCH_DATE") の値を確認しましょう。 nullだったり(id が"db_SEARCH_DATE"のエレメントが存在しない場合や、idのタイプミスで起きる)、"db_SEARCH_DATE"というタグを持つエレメントが複数あるためにcollectionになってたりしてませんか?
<input id="db_SEARCH_DATE" onblur="hoge(this);" type="text" maxlength="7" value="2019/06" />
があるため、「2019/06」が出力されると思っています。
id属性は重複しないはずですよね・・・?となると単一の要素のvalueが取得できるのではないかと考えています。
$this.Doc.IHTMLDocument3_getElementById("db_SEARCH_DATE").valueにしたら、「2019/06」が出力されました。
基本的には「IHTMLDocument3_」のほうが良いのでしょうか?

回答1件
あなたの回答
tips
プレビュー