I've seen numerous solutions for C# but I couldn't get it working in VB.NET. Maybe I am initalizing it wrong? I'd like to execute javascript over a loaded URL in the chromedriver.
My code so far:
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');")
It's not executing. Any help, please? :)
Fixed it. Just add to the top of the code
Imports OpenQA.Selenium.Support.Extensions
and use driver.ExecuteJavaScript("alert(0);")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With