#设置网址。
$Url = "https://www.plexonline.com";
$Username="xxxx";
$Password="xxxx";
$CompanyCode="xxx";
为 IE 创建一个新的 COM 对象。
$IE = New-Object -ComObject internetexplorer.application;
将 IE 设置为全屏。
$IE.FullScreen = $true;
将 IE 设置为可见。
$IE.Visible = $true;
将 IE 导航到指定的 URL。
$IE.navigate($url);
等到 IE 不再忙。
while ($IE.Busy -eq $true)
{
Start-Sleep -Milliseconds 500;
}
将指定的用户名、密码和公司代码插入到各自的字段中。
$IE.Document.getElementById("txtUserID").value = $Username;
$IE.Document.getElementByID("txtPassword").value = $Password;
$IE.Document.getElementByID("txtCompanyCode").value = $CompanyCode;
开始登录过程。
$IE.Document.getElementById("btnLogin_Label").Click();
继续等待,直到 IE 不再忙。
while ($IE.Busy -eq $true)
{
Start-Sleep -Milliseconds 2000;
}
最佳答案
很遗憾,Google 不支持 COM 模型,因此没有提供可在 PowerShell 中使用的 COM 对象。
但是,您可以使用 Start-Process
启动 Google Chrome 进程,然后您可以相应地继续执行其余步骤:
$Url = "https://www.plexonline.com";
$Username="xxxx";
$Password="xxxx";
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))
Start-Process "<path to chrome.exe>" $Url -Credential $Credential -WindowStyle Maximized
关于powershell - 如何使用 PowerShell 自动登录 Chrome。我有一个使用 IE 运行的脚本,但需要使用 Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66143911/