Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net - execute selenium ChromeDriver javascript

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? :)

like image 636
Johnny Avatar asked Nov 19 '17 00:11

Johnny


1 Answers

Fixed it. Just add to the top of the code

Imports OpenQA.Selenium.Support.Extensions

and use driver.ExecuteJavaScript("alert(0);")

like image 60
Johnny Avatar answered Sep 28 '22 03:09

Johnny