0

I'm trying to use the WebDriver DLL via PowerShell. I keep getting the following Exception everytime:

format-default : The following exception occurred while retrieving members: "Could not load file or 
assembly 'WebDriver, Version=2.48.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
The system cannot find the file specified."
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMembers,Microsoft.PowerShell.Commands.FormatDefaultCommand

This is my code:

[Reflection.Assembly]::LoadFile("X:\WebDriver.dll")
[Reflection.Assembly]::LoadFile("X:\Winium.WebDriver.dll")
[Reflection.Assembly]::LoadFile("X:\Elements.Desktop.dll")
[Reflection.Assembly]::LoadFile("X:\Winium.Cruciatus.dll")


$options = [OpenQA.Selenium.Winium.DesktopOptions]::new()
$options

This is my output:

GAC    Version        Location                                                                            
---    -------        --------                                                                            
False  v4.0.30319     X:\WebDriver.dll                                                                    
False  v4.0.30319     X:\Winium.WebDriver.dll                                                             
False  v4.0.30319     X:\Winium.Elements.Desktop.dll                                                      
False  v4.0.30319     X:\Winium.Cruciatus.dll                                                             
format-default : The following exception occurred while retrieving members: "Could not load file or 
assembly 'WebDriver, Version=2.48.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
The system cannot find the file specified."
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMembers,Microsoft.PowerShell.Commands.FormatDefaultCommand

I'm not sure what is wrong over here. Could someone please help me out?

rne18145
  • 1
  • 1

1 Answers1

0

You are not give details, of OS version, PowerShell version, whether you were doing this as Admin or regular user, etc...

Anyway, switch this...

[Reflection.Assembly]::LoadFile("X:\WebDriver.dll")

to this ...

Add-Type -Path "C:\Temp\PSL\WebDriver.dll"

Sure, for the most part, they are for the same goal but try it.

See this blog:

Add-Type vs. [reflection.assembly] in PowerShell

Modules should be in the PSModuelPath, to allow PowerShell to find and autoload them if possible. Though sure, you can explicitly load from any UNC (as noted by your post and the snippet included in my response) but why force that effort.

postanote
  • 15,138
  • 2
  • 14
  • 25
  • Thank you for your response. I figured out that it was a missing DLL dependency. I'm on Windows 10, 64-bit, PS Version 5.1. I gave the load statement in Try Catch and printed the exception. That helped. – rne18145 Apr 20 '20 at 10:38