I've created several Powershell scripts that's using the Selenium Webdriver.
Now I need to add some Javascript functionality to one of them, but I'm unable to figure out how I go about to get the syntax correct.
Attempted to convert the following C# code from this discussion: Execute JavaScript using Selenium WebDriver in C#
And this is what my code looks like at the moment:
# Specify path to Selenium drivers
$DriverPath = (get-item ".\" ).parent.parent.FullName + "\seleniumdriver\"
$files = Get-ChildItem "$DriverPath*.dll"
# Read in all the Selenium drivers
foreach ($file in $files) {
$FilePath = $DriverPath + $file.Name
[Reflection.Assembly]::LoadFile($FilePath) | out-null
}
# Create instance of ChromeDriver
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
# Go to example page google.com
$driver.Url = "http://www.google.com"
# Create instance of IJavaScriptExecutor
$js = New-Object IJavaScriptExecutor($driver)
# Run Javascript to get current url title
$title = $js.executeScript("return document.title")
# Write titel to cmd
write-host $title
But I constantly get the error below when creating instance of IJavaScriptExecutor:
"New-Object : Cannot find type [IJavaScriptExecutor]: make sure the assembly containing this type is loaded."
Can anyone figure out what I'm missing? Is it incorrect code? Missing additional dll's?
Br, Christian