【问题标题】:Not able to click on a link a java link on a site using powershell无法单击链接 使用 powershell 的站点上的 java 链接
【发布时间】:2017-03-31 00:04:38
【问题描述】:

打开站点后,该框架菜单栏内有一个框架是他们的,并且在该菜单栏中 5 按钮是他们的示例:-

搜索(e 下划线,下拉箭头也有搜索)和窗口(W 下划线,下拉箭头也有窗口)我想点击搜索。

我尝试使用href,id,但无法点击搜索。

        $Url = “some site” 
        $Username=”xxx” 
        $Password=”xxx” 

       $IE = New-Object -com internetexplorer.application; 
       $IE.visible = $true; 
       $IE.navigate($url); 
       while ($IE.Busy -eq $true) 

      { 

      Start-Sleep -Milliseconds 2000; 

      }

        $IE.Document.getElementById(“USERNAME”).value = $Username 
         $IE.Document.getElementByID(“PIN”).value=$Password 
        $IE.Document.getElementById(“HardcodedSub”).Click()

        while($ie.busy) {sleep 5} 

        $Link = $ie.Document.getElementsByTagName("a") | where-object {$_.id -eq     'menu_2'}
         $Link.click()


error:-You cannot call a method on a null-valued expression.
At line:25 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull


inspect element:-

<a id="menu_2" tabindex="2" class="menu_unselected_text" href="javascript:window.parent.role_main.cai_main.setActKeyMenuState(2)">S<u>e</u>arch<img border="0" src="/CAisd/img/arrow_asc_bk.png" width="15" height="10"></a>

【问题讨论】:

    标签: powershell powershell-3.0 powershell-4.0


    【解决方案1】:

    为什么不能在下面使用相同的 GetElementById()。

    $Link = $ie.Document.getElementById("menu_2") 
    

    在 PowerShell ISE 中调试或逐行执行并在调用方法之前查看页面完全加载是很好的。

    问候,

    Kvprasoon

    【讨论】:

      猜你喜欢
      • 2020-10-19
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 2020-03-25
      相关资源
      最近更新 更多