PowerShell使用Internet Explorer.Application在下拉列表中选择项目

发布于 2025-02-08 08:59:34 字数 941 浏览 1 评论 0原文

我正在尝试通过PowerShell选择下拉列表。它使用JavaScript。到目前为止,我只能通过获取元素来登录并获得一堆方法。见下文。

# Create an ie com object
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
# Wait for the page to load
while ($ie.Busy -eq $true){ Start-Sleep -Milliseconds 1000; }

# Login
Write-Host -ForegroundColor Green "Attempting to login.";
# Add login details
try
{
    $ie.Document.IHTMLDocument3_getElementsByName("user") = $username
    $ie.Document.IHTMLDocument3_getElementsByName("pass") = $password
    $ie.Document.IHTMLDocument3_getElementsByName("submit")

    Do{Start-Sleep -Milliseconds 100}While($ie.Busy -eq $True)    
}
catch
{
    $_.Exception.Message
}

#get dropdown elementarray
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId')
#get methods
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId') | gm

有人知道如何在占位符中选择特定元素吗?方法太多了,无法适应该帖子。

提前致谢。

I am attempting to select a dropdown item via Powershell. Its using Javascript. So far I'm only achieved to login and get a bunch of methods by getting the Element. See below.

# Create an ie com object
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
# Wait for the page to load
while ($ie.Busy -eq $true){ Start-Sleep -Milliseconds 1000; }

# Login
Write-Host -ForegroundColor Green "Attempting to login.";
# Add login details
try
{
    $ie.Document.IHTMLDocument3_getElementsByName("user") = $username
    $ie.Document.IHTMLDocument3_getElementsByName("pass") = $password
    $ie.Document.IHTMLDocument3_getElementsByName("submit")

    Do{Start-Sleep -Milliseconds 100}While($ie.Busy -eq $True)    
}
catch
{
    $_.Exception.Message
}

#get dropdown elementarray
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId')
#get methods
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId') | gm

Does anybody know how to select a specific element in the placeholder? Methods are too many to fit in the post.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧故 2025-02-15 08:59:34

对于其他任何人,答案是:

($ie.Document.IHTMLDocument3_getElementById('$contentPlaceHolderId') | Where-Object { $_.innerHTML -eq '$DropDownElementName' }).selected = $true

单击按钮是:

$ie.Document.IHTMLDocument3_getElementById('$button').click();

For anybody else the answer is:

($ie.Document.IHTMLDocument3_getElementById('$contentPlaceHolderId') | Where-Object { $_.innerHTML -eq '$DropDownElementName' }).selected = $true

Clicking a button is:

$ie.Document.IHTMLDocument3_getElementById('$button').click();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文