-1

I am trying to execute PowerShell script with Selemiun using Start-Job

Start-Job {
    $Url = 'https://stackoverflow.com/'
    $Driver = Start-SeChrome
    Enter-SeUrl -Url $Url  -Driver $Driver
    }

The script should open Chrome and follow the link. Instead, it just opens Chrome.

Everything works correctly without Start-Job. The only thing I noticed is the lack of a command prompt window with chromedriver.exe running. But judging by the Task Manager, chromedriver.exe starts up

Finding a solution is complicated by the fact that I do not know how to read the errors that occur when starting Start-job.

Jen
  • 1,964
  • 9
  • 33
  • 59
  • 1
    try use runspaces... https://devblogs.microsoft.com/scripting/beginning-use-of-powershell-runspaces-part-1/ – Avshalom Jul 26 '20 at 20:11
  • the scriptblock runs in its own scope. you need to pass the info into the scriptblock. [*grin*] take a look at `Get-Help Start-Job -Parameter InitializationScript`, at `Get-Help Start-Job -Parameter ArgumentList`, and finally at `Get-Help about_Scopes` ... especially the section titled `The Using scope modifier`. – Lee_Dailey Jul 26 '20 at 21:10

2 Answers2

0

Thanks a lot Avshalom for the tip. Validly using PoshRSJob module solved my problem. Selenium is finally working correctly.

0

It would also work with start-threadjob or foreach-object -parallel in powershell 7. You can download the Threadjob module in powershell 5.1

js2010
  • 23,033
  • 6
  • 64
  • 66