我根据Scott Hanselman's blog post上的代码段开发了一个PowerShell脚本:
# install selenium-standalone locally
npm install selenium-standalone --save-dev
# install chrome driver only
./node_modules/.bin/selenium-standalone install --singleDriverInstall=chrome
# start selenium-standalone with chrome driver
$SeleniumProcess = Start-Process "./node_modules/.bin/selenium-standalone" -ArgumentList "start --drivers=chrome" -PassThru -NoNewWindow
# perform a task
Start-Sleep -Seconds 6
# stop selenium-standalone process
Stop-Process -Id $SeleniumProcess.Id
# remove downloaded files
Remove-Item .\node_modules\ -Force -Recurse
Remove-Item .\package-lock.json -Force -Recurse
第一个Remove-Item
无效,因为它抱怨java.exe
由某个进程拥有,我相信它是用来启动node.exe
的{{1}}。 / p>
Scott Hanselman 帖子似乎暗示selenium-standalone
和Start-Process
应该默默地执行,但显然不行。
我在做什么错了?