【发布时间】:2021-09-07 16:09:57
【问题描述】:
我手动打开 Chrome 浏览器并转到“https://www.google.com/”并按 F12 以转到开发者工具。然后我转到控制台并输入localStorage.key(0) 以获取本地存储中第一项的密钥,然后我得到'whatever'。
但是,当我运行以下测试代码时,firstKey 中的返回值为 Empty。
Sub GetLocalStorage()
Dim driverGoogle As Object
Dim firstKey As Variant
Set driverGoogle = CreateObject("Selenium.Chromedriver")
driverGoogle.Get "https://www.google.com/"
driverGoogle.Window.SetSize 1800, 1050
firstKey = driverGoogle.ExecuteScript("localStorage.key(0);")
End Sub
我什至将localStorage.key(0) 更改为不正确的localStorage.aaakey(0),确保ExecuteScript 确实在执行,并且确实 Selenium 引发了错误。
那么,如何获取本地存储键/值?
【问题讨论】:
标签: vba selenium selenium-chromedriver