2

I am not sure what I am missing, but I installed Selenium module under PowerShell 7.1 and I cannot start chrome instance. I followed the steps below (from https://github.com/adamdriscoll/selenium-powershell):

Install-Module -Name Selenium -AllowPrerelease
$driver = start-SeChrome 

I get this error:

start-SeChrome: The term 'start-SeChrome' is not recognized as a name of a cmdlet, function, script file, or executable program.

I also tried running the script from vscode, still the same problem. See the snapshot below.

Edit: I was able to remove the latest Selenium version, and installed module 3.0.1. I had to uninstall the old one, delete the related module folders, kill all the session, and install 3.0.1. Now the command is available, but I am getting this error:

MethodInvocationException: Exception calling ".ctor" with "2" argument(s): "unknown error: cannot find Chrome binary"

See the snapshot below.

I appreciate your help.

enter image description here

enter image description here

tarekahf
  • 738
  • 1
  • 16
  • 42
  • looks like you may have another version of the module loaded in your session already. Close your VSCode and then re-launch and try again to see if the error doesn't resolve or if you get a different error. – TheMadTechnician Feb 04 '22 at 18:41
  • I uninstalled the latest version of Selenium module, and installed version 3.0.1 `Install-Module -Name Selenium -RequiredVersion 3.0.1`. I had to kill the related session, deleted the folders of the module, and install 3.0.1 version, not the command `Start-SeChrome` is available but there is another error. See the updated post please. – tarekahf Feb 04 '22 at 18:45
  • 1
    Take a look at [this answer](https://stackoverflow.com/a/50140554/3245749) to see if that resolves your issue. – TheMadTechnician Feb 04 '22 at 19:11
  • I found the root-cause. Check the answers shortly. – tarekahf Feb 04 '22 at 20:28

3 Answers3

0

Did you put an import statement at the top of your script?

Import-Module "{FullPath}\selenium-powershell\Selenium.psd1"

The "OR" between the Install statement and the Import statement in the docs does not make sense to me. You have to install once just to get the module on your computer, but you have to import at the top of the script so the script can find the installed module.

Darin
  • 1,423
  • 1
  • 10
  • 12
  • What is the `{FullPath}`? In my case, I used `$fullPath = (Get-InstalledModule -Name Selenium).installedlocation; Import-Module "$myPath\Selenium.psd1"` from the PS Command Line Window. Maybe I have to put it in a script file? Let me try it. – tarekahf Feb 04 '22 at 18:05
  • I have updated the post above. See the snapshot https://i.stack.imgur.com/upbAc.png. It is not working. What I am doing worng? – tarekahf Feb 04 '22 at 18:12
  • I see in one of the above comments you say "I found the root-cause". Glad to hear it. I just got home and tried exact what you are showing and I'm getting a different message: "ChromeDriver only supports Chrome version 83". So the script is probably fine, just something wrong related to Chrome. – Darin Feb 04 '22 at 22:42
  • Did you check my answer? Sadly, it's a hit and miss process. I read so many articles until I figured out what to do. – tarekahf Feb 04 '22 at 22:52
  • tarekahf, sorry, I missed the answer, was focused on the comments. Thanks for sharing the answer. – Darin Feb 04 '22 at 23:13
  • I hope it worked out for you. – tarekahf Feb 06 '22 at 05:48
0

I solved the problem by following the steps below:

  • Installed the stable version of Selenium PowerShell module which is at the time is 3.0.1. When I installed the latest version 4.x it was not working for some reason.
  • To remove the installed version, use PowerShell commands to remove it with Force, delete the related folders, and kill all related sessions.
  • In the installed module path, put the file chromedriver.exe in ...\PowerShell\Modules\Selenium\3.0.1\assemblies which is compatible with with the installed version of Chrome. Rename the existing one to be on the safe side.
  • To get the compatible driver, check https://chromedriver.chromium.org/downloads.
  • Kill the sessions, and try again.
tarekahf
  • 738
  • 1
  • 16
  • 42
0

In the installed module path, put the file chromedriver.exe in ...\PowerShell\Modules\Selenium\3.0.1\assemblies which is compatible with with the installed version of Chrome. Rename the existing one to be on the safe side. To get the compatible driver, check https://chromedriver.chromium.org/downloads.

This helped me