为什么Getelementbyid返回一个空值表达式?我知道这个想法存在

时间:2014-02-27 22:58:36

标签: powershell

我知道这是在我写这篇文章的时候。我们今天经历了域名切换,现在它正在Powershell.exe -windowstyle中隐藏了返回空值表达式。

我将其删除并在每个getelementby上收到错误。目的是提示用户输入用户名和密码,并按顺序将其传递给两个站点。我仔细检查了我的元素ID。

PowerShell.exe -windowstyle hidden {
    $url = "https://www.e-access.att.com/webet/DeltekTC/welcome.msv"
    $x=""
    $y=""

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "Deltek Logon Assistant"
    $objForm.Size = New-Object System.Drawing.Size(300,175)
    $objForm.StartPosition = "CenterScreen"

    $objForm.KeyPreview = $True
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {$x=$objTextBox1.Text;$y=$objTextbox2.Text;$objForm.Close()}})
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,105)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.Add_Click({$x=$objTextBox1.Text;$y=$objTextbox2.Text;$objForm.Close()})
    $objForm.Controls.Add($OKButton)

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(150,105)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.Add_Click({$objForm.Close()})
    $objForm.Controls.Add($CancelButton)

    #- User
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,10)
    $objLabel.Size = New-Object System.Drawing.Size(280,20)
    $objLabel.Text = "Username:"
    $objForm.Controls.Add($objLabel)

    $objTextBox1 = New-Object System.Windows.Forms.MaskedTextBox
    $objTextBox1.Location = New-Object System.Drawing.Size(10,30)
    $objTextBox1.Size = New-Object System.Drawing.Size(260,20)
    $objForm.Controls.Add($objTextBox1)


    #-Pass
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,55)
    $objLabel.Size = New-Object System.Drawing.Size(280,20)
    $objLabel.Text = "Password:"
    $objForm.Controls.Add($objLabel)

    $objTextBox2 = New-Object System.Windows.Forms.MaskedTextBox
    $objTextBox2.Location = New-Object System.Drawing.Size(10,75)
    $objTextBox2.Size = New-Object System.Drawing.Size(260,20)
    #- this is what makes your password show up as **
    $objTextBox2.PasswordChar = '*'
    $objForm.Controls.Add($objTextBox2)

    $objForm.Topmost = $True

    $objForm.Add_Shown({$objForm.Activate()})
    [void] $objForm.ShowDialog()

    $x
    $y


    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($url);

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("userid").value = $x
    $ie.Document.getElementByID("password").value= $y
    $ie.Document.getElementById("btnSubmit").Click();

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("successOK").Click();

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("uid").value = $x
    $ie.Document.getElementByID("passField").value= $y
    $ie.Document.getElementById("loginButton").Click();
}

1 个答案:

答案 0 :(得分:0)

您的getElementByID似乎工作正常,但您的变量未设置,因此您要将网页上的用户名和密码字段的值设置为“”($x和{{1的值}})。
试试这个,看看你是否会得到更好的结果。将确定按钮更改为:

$y

然后,在您拨打电话以显示表单集$OKButton.Add_Click({$objForm.Close()}) $x之后:

$y

据我所知,这应该照顾它,但如果没有登录该网站,我将无法100%确定。

相关问题