powershell - Powershell 自动登录到网站.....$ie.Document.getElementsByClassName
问题描述
我正在尝试设置一个 PowerShell,它将让我登录到我儿子的学校门户并提交所需的表格。我必须每天做一个,并且得到了可以编写脚本的好主意。该脚本与错误一起在下面
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
$username="Username"
$password="Password"
$ie.Navigate("https://parents.genesisedu.com/hasbrouckheights/parents?module=home&studentid=1000333&action=form")
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}
$usernamefield = $ie.document.getElementByID('j_username')
$usernamefield.value = "$username"
$passwordfield = $ie.document.getElementByID('j_password')
$passwordfield.value = "$password"
$Link = $ie.Document.getElementsByClassName(“saveButton”)[0].value="Login"
$Link.click()
Method invocation failed because [System.String] does not contain a method named 'click'.
At line:19 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
我尝试了很多变化,但似乎无法让它点击“登录”按钮。任何帮助将不胜感激......
*************** 网站信息 ************************
<input type="submit" class="saveButton" style="color: #000000;background-color: #e0e0e0; font-weight: 500;" value="Login">
<input type="button" class="saveButton" value="Forgot My Password" style="background-color:#e0e0e0; border:transparent; cursor:pointer;color:#000; font-size: 12pt; font-weight:500" onclick="forgotMyPassword();">
谢谢
解决方案
您当前在调用之前将字符串值分配给"Login"
,因此出现错误。$Link
Click()
改变这个:
$Link = $ie.Document.getElementsByClassName(“saveButton”)[0].value="Login"
... 至:
$Link = $ie.Document.getElementsByClassName(“saveButton”)[0]
推荐阅读
- libtorrent - 慢速磁盘的 Libtorrent 设置
- c++ - 普通循环未使用 gcc 4.8.5 自动矢量化
- node.js - 将 Angular CLI 升级到最新版本?
- java - 如何在 Eclipse 中为 SQL Server JDBC 驱动程序配置集成身份验证?
- php - 使用 preg_match() 并替换为将 URL 转换为文本中的锚标记
- r - 基于前两列合并两个数据帧,在R中以不同方式排列相同的信息
- php - 如何在 php 数组中添加冒号?
- python - Python 读取 csv 文件
- sql - Oracle/SQL - 基于参数的动态列
- amazon - 亚马逊 MWS CreateShipment 每次都与 Fedex 一起失败,没有真正的错误