msedgedriverを使用してGetActiveElementなどでElementIDを取得した際に
それがHTML上のどの要素なのかを特定したいです。
EdgeのデベロッパツールでIDを検索かけてみたりしたのですが
見つけられません
方法はありませんか?
PowerShell
1Class WebDriver{ 2 3 [Diagnostics.Process] $Process 4 [UInt16] $LocalPort 5 6 WebDriver([String] $WebDriver){ 7 $This.Process = start $WebDriver -WindowStyle Hidden -PassThru 8 do{ 9 $This.LocalPort = Get-NetTCPConnection -OwningProcess $This.Process.Id -LocalAddress "127.0.0.1" -State Listen -ErrorAction SilentlyContinue|% LocalPort 10 }while($This.LocalPort -eq 0) 11 12 } 13 14 [PsCustomObject] Get([String] $Url){ 15 $rst = Invoke-RestMethod -Method Get -uri "http://localhost:$($This.LocalPort)$Url" 16 return $rst.value 17 } 18 [PsCustomObject] Post([String] $Url, [PsCustomObject] $Arg){ 19 $Json = $Arg|ConvertTo-Json -Compress 20 $Body = [Text.Encoding]::UTF8.GetBytes($Json) 21 $rst = Invoke-RestMethod -Method Post -uri "http://localhost:$($This.LocalPort)$Url" -body $Body -ContentType Application/json 22 return $rst.value 23 } 24 [WebSession] NewSession(){ 25 $Body = @{capabilities=@{}} 26 $Result = $This.Post("/session",$Body) 27 return [WebSession]::new($This, $Result.SessionID) 28 } 29} 30 31Class WebSession{ 32 33 [WebDriver] $WebDriver 34 [String] $SessionID 35 36 WebSession([WebDriver] $WebDriver, [String] $SessionID){ 37 $This.WebDriver = $WebDriver 38 $This.SessionID = $SessionID 39 } 40 [PsCustomObject] NavigateTo([String] $Url){ 41 $body = @{url=$Url} 42 return $This.WebDriver.Post("/session/$($This.SessionID)/url",$body) 43 } 44 [WebElement] GetActiveElement(){ 45 $Result = $This.WebDriver.Get("/session/$($This.SessionID)/element/active") 46 return [WebElement]::New($This, $Result."element-6066-11e4-a52e-4f735466cecf") 47 } 48} 49 50Class WebElement{ 51 52 [WebDriver] $WebDriver 53 [WebSession] $WebSession 54 [String] $ElementID 55 56 WebElement([WebSession] $WebSession, [String] $ElementID){ 57 $This.WebDriver = $WebSession.WebDriver 58 $This.WebSession = $WebSession 59 $This.ElementID = $ElementID 60 } 61} 62 63 64$EdgeDriver = [WebDriver]::new("D:\Items\Programing\PowerShell\ps\tool\WebDriver\msedgedriver.exe") 65$sess = $Edge.NewSession() 66$sess.NavigateTo("https://teratail.com/") 67$Element = $sess.GetActiveElement() 68 69# これがHTML上の何処に存在しているのか探したい 70$Element.ElementID 71 72$EdgeDriver.Process.Kill()
あなたの回答
tips
プレビュー