简体   繁体   中英

Selenium in powershell does not work with Start-Job command

I have the following .dll files in order to run selenium through powershell: 在此处输入图片说明

You can ignore the extension files. Basically what I want to have happen is to use the Start-Job command in order to open two chrome browsers at the same time, and go to different url's.

Here is my script:

temp.ps1

# set the location to the current one where the dll's are
Set-Location -Path $args[0]
Get-ChildItem -Filter "*.dll" | ForEach-Object { Add-Type -Path $_.Name } # this will get all the dll's

# start chrome
$options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$options.BinaryLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$chrome = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)
$chrome.Navigate().GoToUrl("http://www.google.com")

Running this opens a chrome window at google.com在此处输入图片说明

For now, I just want to test to see if I can open two different chrome apps at the same time and have them both go to google.com

Here is that script:

在此处输入图片说明

Running through powershell window does not do what I expect? It opens two chrome browsers but does not navigate to them, also checking the job details reveals no error messages?

在此处输入图片说明

Posting here for visibility - hopefully this saves someone else a bit of stress:

My function was working perfectly when run directly, but failed quietly whenever it was run via Start-Job. It would cease right at the point of starting the ChromeDriver service.

I resolved this problem by instructing ChromeDriver to hide the command prompt window, by passing in "HideCommandPromptWindow" during the service instantiation.

# Hook into our Chrome session on the Debugger port
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.debuggerAddress = "127.0.0.1:1111"

# Pass our configuration into ChromeDriver.exe
$ChromeService = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService()
$ChromeService.HideCommandPromptWindow = $true

# Start ChromeDriver
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeService, $ChromeOptions)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM