Using WebDriver in LINQPad is pain
Pain #1: Prevented installing Selenium native web drivers(such as "Selenium.Chrome.WebDriver")
In my previous post(https://forum.linqpad.net/discussion/1680/please-dont-prevent-installing-native-package-in-linqpad), LINQPad added support for installing native libraries, this is good.
But packages like Selenium.Chrome.WebDriver does not provide any AssemblyReferences or native libraries, instead, it provides an exe called "chromedriver.exe" that WebDriver used to do bridge to the browser.
Pain #2: Did not using the ".targets" file in nuget package
This "Selenium.Chrome.WebDriver" provide a targets file to code easily, the file like this:
Specifically, LINQPad5 did not respect the BeforeTargets="AfterBuild" field, and not copy anything to "%LocalAppData%\LINQPad\ProcessServer5AnyCPUB" or "%Temp%/LINQPad5/_sgxdmyqf" folder.
LINQPad should copy the "chromedriver.exe" to one of that folder so that I can write code easily and don't need to find where the "chromedriver.exe" is.
In my previous post(https://forum.linqpad.net/discussion/1680/please-dont-prevent-installing-native-package-in-linqpad), LINQPad added support for installing native libraries, this is good.
But packages like Selenium.Chrome.WebDriver does not provide any AssemblyReferences or native libraries, instead, it provides an exe called "chromedriver.exe" that WebDriver used to do bridge to the browser.
Pain #2: Did not using the ".targets" file in nuget package
This "Selenium.Chrome.WebDriver" provide a targets file to code easily, the file like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyChromeDriverToBin" BeforeTargets="AfterBuild">
<PropertyGroup>
<ChromeDriverSrcPath>$(MSBuildThisFileDirectory)..\driver\chromedriver.exe</ChromeDriverSrcPath>
<ChromeDriverTargetPath Condition=" '$(ChromeDriverTargetPath)' == '' ">$(TargetDir)</ChromeDriverTargetPath>
</PropertyGroup>
<Copy SourceFiles="$(ChromeDriverSrcPath)" DestinationFiles="$(ChromeDriverTargetPath)chromedriver.exe" SkipUnchangedFiles="true"></Copy>
</Target>
</Project>
Specifically, LINQPad5 did not respect the BeforeTargets="AfterBuild" field, and not copy anything to "%LocalAppData%\LINQPad\ProcessServer5AnyCPUB" or "%Temp%/LINQPad5/_sgxdmyqf" folder.
LINQPad should copy the "chromedriver.exe" to one of that folder so that I can write code easily and don't need to find where the "chromedriver.exe" is.
Comments
FWIW, this should be fixed in .NET Core 3 (there will be a new version of LINQPad to support this when it's released). It has the concept of a "runtimes" folder where you can put native dependencies via convention-based folders.
Had the same issue and my workaround is to find and set the path to the selenium-manager.exe which then takes care of finding and loading chromedriver. You could just set the path outside of LinqPad, but this method should work with updated packages (assuming they follow the same structure).
One gotcha is that the check is performed in a static class in selenium and so if I forget to call this method, I can't just add the call to this method and rerun the script, but I have to close the script or close linqpad and re-open the script.