Open ghost opened 3 years ago
I get a Class Not Registered on my 64bit Windows when I try to run CurrentURL. However it works when I replace the "With" structure with:
CurrentURL = Execute(CMD_GET_CURRENT_URL, data)
or
CurrentURL = Replace(Execute(CMD_GET_CURRENT_URL, Data), "data:,", "")
Maybe this issue should be classified as a "bug", as it may require a 64-bit user to install a 32-bit version of MS Script Control dll for it to work? Google "Class Not Registered script control vba" for more info. I'll submit this as a separate issue https://github.com/uezo/TinySeleniumVBA/issues/44...
ありがとうございます。 URLに日本語がある場合はデコードする必要があります。そこで javascript の decodeURL を使うように変更しました。
Public Function CurrentURL(Optional ByVal SessionId As String = vbNullString) As String
Dim Data As New Dictionary
If SessionId <> vbNullString Then
Data.Add "sessionId", SessionId
End If
Dim encodeURL As String
encodeURL = Execute(CMD_GET_CURRENT_URL, Data)
CurrentURL = Me.ExecuteScript("return decodeURI('" & encodeURL & "')")
End Function
確認用です。
Sub TestforCurrentURL()
Dim Driver As WebDriver
Set Driver = New WebDriver
Driver.Chrome "chromedriver.exe"
Driver.OpenBrowser
Driver.Navigate "E:\Work2\テスト.html"
MsgBox Driver.CurrentURL
Driver.CloseBrowser
Driver.Shutdown
Set Driver = Nothing
End Sub
この場合の結果は以下になります。 encodeURL ⇒ file:///E:/Work2/%E3%83%86%E3%82%B9%E3%83%88.html CurrentURL ⇒ file:///E:/Work2/テスト.html
@ezagdd excellent, thanks!
TinySeleniumVBA WebDriver.cls に対して、CurrentURL のメソッド追加。