为了通过powershell运行selenium,我有以下.dll
文件:
您可以忽略扩展文件。基本上,我希望发生的是使用Start-Job
命令,以便同时打开两个chrome
浏览器,并转到不同的url。
下面是我的脚本:
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")
运行此命令将在google.com打开一个chrome窗口
现在,我只想测试一下是否可以同时打开两个不同的chrome应用程序,并让它们都转到google.com
以下是该脚本:
通过powershell窗口运行并不能完成我所期望的事情?它会打开两个chrome浏览器,但不会导航到它们,检查作业详细信息也不会显示错误消息吗?
发布于 2021-04-16 09:14:38
在这里发帖是为了提高知名度--希望这能减轻别人的压力:
我的函数在直接运行时运行得很好,但无论何时通过Start-Job运行,都会悄悄地失败。它将在启动ChromeDriver服务时立即停止。
我通过在服务实例化期间传入"HideCommandPromptWindow“,指示ChromeDriver隐藏命令提示符窗口,从而解决了这个问题。
# 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)
https://stackoverflow.com/questions/50195094
复制相似问题