【问题标题】:PowerShell Button not clickingPowerShell按钮未单击
【发布时间】:2018-04-30 17:15:27
【问题描述】:

我想点击这个按钮:(Google.com)

<input value="Google-Suche" aria-label="Google-Suche" name="btnK" type="submit" jsaction="sf.chk">

这是我的代码:

$ie = New-Object -Com InternetExplorer.Application
$ie.Visible = $true
$ie.navigate("http://google.com")
Start-Sleep 5
$ie.Document.IHTMLDocument3_getElementById("lst-ib").value = $Keywords
$Link = $ie.Document.getElementsByTagName("input") | Where-Object {$_.name -eq "btnK"}
$Link.Click()

如果我运行它,一切正常,但它没有按下按钮。但是,如果我手动执行 $Link.Click() 它可以工作。

知道如何解决这个问题吗?还是我的代码有一些缺陷?我没有收到任何错误消息。我已经尝试在单击按钮之前输入Start-Sleep 10,但这也不起作用。

PS:我使用 Google 只是为了测试。此代码将用于另一个站点,但我目前无法访问它。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    你应该在 ie 忙的时候睡觉。这对我有用:

    $ie = New-Object -Com InternetExplorer.Application
    $ie.Visible = $true
    $ie.navigate("http://google.com")
    while($ie.Busy) { Start-Sleep -Milliseconds 100 }
    $ie.Document.IHTMLDocument3_getElementById("lst-ib").value = "cheesecake"
    $Link = $ie.Document.getElementsByTagName("input") | Where-Object {$_.name -eq "btnK"}
    $Link.Click()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多