使用powershell自动登录网站 [英] Auto Login to a website using powershell

查看:82
本文介绍了使用powershell自动登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行我的 powershell 脚本时收到以下错误消息

I am getting following error message when i am running my powershell script

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Test.ps1:17 char:1
+ $usernamefield.value = $username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Test.ps1:20 char:1
+ $passwordfield.value = $password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Method invocation failed because [System.DBNull] does not contain a method named 'click'.
At C:\Test.ps1:23 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound`

我的脚本:

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible

$usernmae="test"

$password="test1"

$ie.Navigate("https://website.com/login")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$usernamefield = $ie.document.getElementByID('ysi_email')
$usernamefield.value = $username

$passwordfield = $ie.document.getElementByID('ysi_password')
$passwordfield.value = $password

$Link = $ie.document.getElementByID('ysi_btn_login')
$Link.click()

我似乎无法理解这里的问题,我已经查看了 stackoverflow 中的其他示例,但仍然找不到问题.

I cant seem to understand the problem here, i have looked into other examples within stackoverflow but i still cant find the problem.

在另一个 Python 脚本示例中,相同的 id 可以正常工作.

The same id works fine in another example in a python script.

这是一个截图

推荐答案

问题来自 ID 对象 'ysi_email', 'ysi_password' 和 <在 https://website.com/login 加载的文档的 DOM 中找不到 code>'ysi_btn_login'.

The problem comes from the fact that object of IDs 'ysi_email', 'ysi_password' and 'ysi_btn_login' are not found in the DOM of the document loaded at https://website.com/login.

为了解决您在 Chrome、Firerfox 或 Explorer 中加载文档时遇到的问题(按 F12)并检查您要查找的对象.

To solve your trouble load your document in Chrome, or Firerfox or Explorer with the developpers tools activated (Press F12) and inspect the objects you want to find.

根据您的评论,这是一个可行的解决方案:

Here is a working solution according to your comments :

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible

$username="test@toto.fr"

$password="test1"

$ie.Navigate("https://To your detailled URL")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$usernamefield = $ie.document.getElementByID('ysi_email')
$usernamefield.value = "$username"

$passwordfield = $ie.document.getElementByID('ysi_password')
$passwordfield.value = "$password"

$Link = $ie.document.getElementByID('ysi_btn_login')
$Link.click()

$ie.Quit()

<小时>

在这里你可以看到我的结果.


Here you can see the result for me.

这篇关于使用powershell自动登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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