windows - 方法 "getElementsByClassName"无法识别

标签 windows internet-explorer powershell

我想启动 Windows 资源管理器并登录网站。登录后我想单击注销文本链接。但我收到此错误:

Method invocation failed because [mshtml.HTMLDocumentClass] doesn't contain a
method named 'getElementsByClassName'
At C:\Users\ntando.ntuli\Desktop\test.ps1:29 char:43
+  $Link=$ie.Document.getElementsByClassName <<<< ("underline") | Where-Object {$_.ClassName -eq "underline"}
    + CategoryInfo          : InvalidOperation: (getElementsByClassName:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Here is the code I am using

$IE = New-Object -COM InternetExplorer.Application;
$IE.Visible = $true;
$IE.Navigate("http://192.168.2.73:6500/ouaf/loginPage.jsp");

# Wait a few seconds and then launch the executable.
while ($IE.Busy -eq $true) {
  Start-Sleep -Milliseconds 2000;
}

# The following UsernameElement, PasswordElement, and LoginElement need to be
# modified first.  See the notes at the top of the script for more details.

$elementMatchText = "You are logged in as English System"
$IE.Document.getElementById("userId").value = "username"
$IE.Document.getElementByID("password").value="password"
$IE.Document.getElementById("loginButton").Click()

while ($IE.Busy -eq $true) {
  Start-Sleep -Milliseconds 2000; 
} 

#Logout textlink classname
$Link = $ie.Document.getElementsByClassName("underline") |
        Where-Object {$_.ClassName -eq "underline"}
$Link.Click()

最佳答案

看来您只能在文档的 documentElement 属性上调用 getElementsByClassName:

$ie.Document.documentElement.getElementsByClassName("underline")

关于windows - 方法 "getElementsByClassName"无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34785024/

相关文章:

windows - SetupDiGetClassDevs 是否按照记录与设备实例 ID 一起使用?

internet-explorer - 如何在IE中制作方框阴影?

powershell - 将行转为列的更好替代方案

powershell - 选择字符串-管道输出时的模式输出

c++ - GetShortPathName 不可预测的结果

windows - 学习 Windows 驱动程序开发的最佳资源是什么?

windows - Windows 10 64 位上的 RabbitMQ 3.6.6 - 未检测到 Erlang

javascript - Internet Explorer 中的元素在滚动时跳跃

css - IE 不遵守 :hover on element

powershell - Powershell递归文件名读取并重命名