方法"getElementsByClassName";未识别 [英] Method "getElementsByClassName" not recognized

查看:104
本文介绍了方法"getElementsByClassName";未识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to start Windows Explorer and login to a website. After logging in I want to click logout textlink. But I am getting this error:

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

这是我正在使用的代码

$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()

推荐答案

似乎您只能在Document的documentElement属性上调用getElementsByClassName:

It seems that you can only call getElementsByClassName on the documentElement property of the Document:

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

这篇关于方法"getElementsByClassName";未识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆