PowerShell的:如何preSS网页上的一个按钮,如果你不知道该按钮ID [英] Powershell: How to press a button on a web page if you don't know the button ID

查看:228
本文介绍了PowerShell的:如何preSS网页上的一个按钮,如果你不知道该按钮ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图填补了我的用户名和密码的特定网页,然后在preSS的登录按钮,所有这些都通过PowerShell的自动完成。

问题是,我无法找到在HTML源$ C ​​$ c中的登录按钮的ID。

我曾尝试使用下面的命令:

  $链接= $ ie.Document.getElementsByTagName('A')|其中,对象{$ _。'注册'的innerText -match}

但是这并没有任何工作。

其中任何一个PS命令来使用,如果我想preSS的登录按钮?想法

该HTML code是如下:

 < D​​IV CLASS =登陆GT&;
    < D​​IV CLASS =内容>
        < D​​IV CLASS =第1>登录或创建<一个ID =ctl00_HeaderUserControl_LoginUserControl_hypNewAccount的href =/认证/ registerprovider.aspx?>新建帐户< / A>< / DIV>
        < D​​IV CLASS =小节-2>
            <跨度类=海军大胆>什么是您的电子邮件地址<?/ SPAN>
            < D​​IV CLASS =缩进>
                <跨度类=大胆>电子邮件:< / SPAN>
                <输入ID =表示loginEmail级=文本框TYPE =文本MAXLENGTH =100的tabindex =1/>
                < IMG类=Ajax-loader在SRC =/内容/图像/科研/全球/ transparent.gifALT =/>
            < / DIV>
            < D​​IV CLASS =无效的电子邮件>< / DIV>
        < / DIV>
        < D​​IV CLASS =小节-3>
            <跨度类=海军大胆>你知道你的密码<?/ SPAN>
            < D​​IV>
                <输入ID =passwordNotKnownNAME =passwordSwitch类型=电台检查=选中/>
                <标签=NOPASSWORD>不,我不知道我的密码或我是新< /标签>
            < / DIV>
            < D​​IV>
                <输入ID =passwordKnownNAME =passwordSwitch类型=电台/>
                <标签=NOPASSWORD>是的,我的密码是:< /标签>
                <输入ID =loginPassword级=文本框TYPE =密码MAXLENGTH =50的tabindex =2/>
            < / DIV>
            < D​​IV CLASS =无效的密码>< / DIV>
            < D​​IV CLASS =错误>< / DIV>
        < / DIV>
        < D​​IV CLASS =小节-4>
            <按钮式=按钮级=登录按钮greenButton的tabindex =4>登录< /按钮>
            < A HREF =JavaScript的:无效(0);类=取消链接>取消< / A>
            <输入ID =stayLoggedIn类型=复选框的tabindex =3/>
            <标签=stayLoggedIn>在&LT保持登录状态; /标签>
        < / DIV>
    < / DIV>
    < D​​IV CLASS =重设密码>
        < D​​IV CLASS =第1>你想重置密码< / DIV>
        < D​​IV CLASS =小节-2>选择<跨度类=大胆>是< / SPAN>将重置您的密码和电子邮件临时密码:LT;跨度类=重复的电子邮件>< / SPAN>< / DIV>
        < D​​IV CLASS =小节-3>
            < D​​IV CLASS =中心>
                <按钮类=重置密码键式=键>是< /按钮>
                <按钮类=拒收重置密码键式=键&GT否LT; /按钮>
            < / DIV>
        < / DIV>
    < / DIV>
< / DIV>


解决方案

作为@杰米 - 泰勒提到的登录按钮其实是在一个按钮。

您不仅可以通过该ID,但也可以通过使用类名 document.documentElement.getElementsByClassName 访问它。请注意这个函数会返回元素的列表,页面上有一个元素可以有相同的类。

修改
我错了:为了有 getElementsByClassName 你要调用它 document.documentElement中而不是文件

I'm trying to fill in my username and password on a certain web page and then the press the "sign-in" button, all automatically via Powershell.

The problem is that I cannot find the ID of the sign-in button in the html source code.

I have tried to use the command:

$link = $ie.Document.getElementsByTagName('A') | where-object {$_.innerText -match 'sign in'}

but this didn't worked either.

Any thoughts which PS command to use if I want to press the 'sign in' button?

The HTML code is as follows:

<div class="login">
    <div class="content">
        <div class="subsection-1">Sign in or create a <a id="ctl00_HeaderUserControl_LoginUserControl_hypNewAccount" href="/authentication/registerprovider.aspx?">new account</a></div>
        <div class="subsection-2">
            <span class="navy bold">What is your email address?</span>
            <div class="indent">
                <span class="bold">Email:</span>
                <input id="loginEmail" class="text-box" type="text" maxlength="100" tabindex="1" />
                <img class="ajax-loader" src="/content/images/research/global/transparent.gif" alt="" />
            </div>
            <div class="invalid-email"></div>
        </div>
        <div class="subsection-3">
            <span class="navy bold">Do you know your password?</span>
            <div>
                <input id="passwordNotKnown" name="passwordSwitch" type="radio" checked="checked" />
                <label for="noPassword">No, I don't know my password or I'm new .</label>
            </div>
            <div>
                <input id="passwordKnown" name="passwordSwitch" type="radio" />
                <label for="noPassword">Yes, my password is:</label>
                <input id="loginPassword" class="text-box" type="password" maxlength="50" tabindex="2" />
            </div>
            <div class="invalid-password"></div>
            <div class="error"></div>
        </div>
        <div class="subsection-4">
            <button type="button" class="login-button greenButton" tabindex="4">Sign in</button>
            <a href="javascript:void(0);" class="cancel-link">Cancel</a>
            <input id="stayLoggedIn" type="checkbox" tabindex="3" />
            <label for="stayLoggedIn">Stay signed in</label>
        </div>
    </div>
    <div class="reset-password">
        <div class="subsection-1">Would you like to reset your password?</div>
        <div class="subsection-2">Choosing <span class="bold">yes</span> will reset your password and email a temporary password to: <span class="repeat-email"></span></div>
        <div class="subsection-3">
            <div class="center">
                <button class="reset-password-button" type="button">Yes</button>
                <button class="do-not-reset-password-button" type="button">No</button>
            </div>
        </div>
    </div>
</div>

解决方案

As @Jamie-Taylor mentioned the login button is in fact a button.

You can access it not only by the id but also by the class name using document.documentElement.getElementsByClassName. Please notice this function will return list of elements as more than one element on page can have the same class.

EDIT I was wrong: in order to have getElementsByClassName you have to call it on document.documentElement instead of document

这篇关于PowerShell的:如何preSS网页上的一个按钮,如果你不知道该按钮ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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