Attribute内のリンクテキストを取得する【Selenium Basic × ExcelVBA】
Shadowroot内のリンクテキストを取得するにはどうしたらいいかの質問の返答用
Attributeメソッドを使用して属性の値を取得する
要素を取得後その要素の属性の値を取得 要素.Attribute("属性名")
属性が多くてまとめて一旦とりたいって場合は要素.Attribute("outerHTML")で纏めて取得しても可
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
実際に使用したサンプルコード
Option Explicit
Public Sub Sample()
'driverでChromDriverを使えるようにする
Dim driver As New Selenium.ChromeDriver
'Web要素を入れる変数
Dim 要素 As Selenium.WebElement
With driver
.Get "https://vba.company/samplepage/5/"
Set 要素 = .ExecuteScript("return document.querySelector('#post-494 > div.entry-body > my-element').shadowRoot.querySelector('p:nth-child(5) > a')")
MsgBox 要素.Attribute("href")
End With
End Sub