vb.net - 执行 selenium ChromeDriver javascript

Joh*_*nny 5 javascript vb.net selenium

我见过很多 C# 解决方案,但我无法让它在 VB.NET 中工作。也许我初始化错误?我想通过 chromedriver 中加载的 URL 执行 javascript。

到目前为止我的代码:

Dim chromeOptions As New OpenQA.Selenium.Chrome.ChromeOptions()

chromeOptions.AddUserProfilePreference("profile.default_content_setting_values.images", 2)

Dim driverService = ChromeDriverService.CreateDefaultService()

driverService.HideCommandPromptWindow = True

driver = New ChromeDriver(driverService, chromeOptions)

Dim js As IJavaScriptExecutor = TryCast(driver, IJavaScriptExecutor)

driver.Navigate.GoToUrl("https://www.google.com/")

js.ExecuteScript("alert('hello world');")
Run Code Online (Sandbox Code Playgroud)

它没有执行。有什么帮助吗?:)

Joh*_*nny 5

修复。只需添加到代码顶部即可

Imports OpenQA.Selenium.Support.Extensions
Run Code Online (Sandbox Code Playgroud)

并使用 driver.ExecuteJavaScript("alert(0);")