如何使用powershell在谷歌chrome中自动化网页



在导航到url时,我有不同的按钮,我想自动点击所有按钮,还想将一些数据提取到文件中,并在使用powershell脚本失败时发送带有附件的电子邮件。我刚开始写剧本,但无法继续写下去。请提出建议。

代码:

$ie=Start-Process -FilePath "C:Program Files (x86)GoogleChromeApplicationchrome.exe" -ArgumentList "abc.aspx"
$ie.Document.getElementsByName('').click( )

错误:不能对空值表达式调用方法。行:2字符:2

您正在将Powershell与Javascript相结合。变量$ie是空的,因为你没有使用-PassThru,但即使你使用了,它也不会返回网站的内容,因为chrome.exe没有这样做。

但是,您可以使用InvokeWebrequest来获取网站的内容:

$response = Invoke-WebRequest -Uri "google.com"

然后您可以使用$response对象:

$response.ParsedHTML.getElementsByName('test').click()

最新更新