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.