【问题标题】:InternetExplorer.Application, click checkbox and PowerShellInternetExplorer.Application,单击复选框和 PowerShell
【发布时间】:2019-04-01 04:49:04
【问题描述】:

我在选择复选框时遇到问题。我已经能够通过 ID 标签成功登录和导航,但是这个没有。它唯一的标签是类型和类。

我可以使用 $ie.document.IHTMLDocument3_getElementByTagName("input") 找到此部分,但我找不到任何使用它的方法。

这是我正在使用的 html:

<th class="cText sorting_disabled cHeader" rowspan="1" colspan="1" style="width: 5px;" aria-label="">
    <input type="checkbox" class="selectall"> 
</th>

到目前为止我所拥有的:

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.visible = "true"
$ie.navigate("https://some.site.com") 

while($ie.Busy) { Start-Sleep -Milliseconds 100 }

# login 
$usernameField = $ie.document.IHTMLDocument3_getElementByID("userid")
$passwordField = $ie.document.IHTMLDocument3_getElementByID("Password")
$usernameField.value = "email@domain.com"
$passwordField.value = "supercoolpassword"
$btn_Submit = $ie.document.IHTMLDocument3_getElementByID("btn_signIn")
$btn_Submit.click() 

# go to downloads page 
$ie.navigate("https://some.site.com/pages/mydownloads.aspx") 

# selectall packages to download has me clueless

当复选框被点击时,结果应该是所有的复选框都应该被勾选。

【问题讨论】:

    标签: powershell internet-explorer


    【解决方案1】:

    这是常见的地方,因此,您必须以不同的方式处理。

    $SiteSource.AllElements | Where{$_.TagName -eq 'input'}
    

    或者,就像它是一个按钮

    ($ie.Document.IHTMLDocument3_getElementsByTagName('button') | 
    Where-Object innerText -eq 'SIGN IN').Click()
    

    但是您如何在站点上行走以获取所需的对象?

    我在做出编码决定之前经常使用的一种方法。

    $SiteSource = Invoke-WebRequest -Uri 'SomeUrl'
    
    # single form site
    $SiteSource.Forms | Format-List -Force
    
    
    # multi-form sites
    $SiteSource.Forms[0] | Format-List -Force
    $SiteSource.Forms[1] | Format-List -Force
    
    # Check for what can be used.
    $SiteSource.Forms.Fields
    $SiteSource.InputFields
    

    然后一旦收集了上面的...代码,可以找到和使用。

    $ie = New-Object -com InternetExplorer.Application 
    $ie.visible=$true
    $ie.navigate('SomeUrl') 
    
    while($ie.ReadyState -ne 4) {start-sleep -m 100}
    
    $UserID = $ie.document.getElementsByTagName('INPUT') | 
    Where-Object {$($_.Name) -match 'userid'}
    $UserId.value = 'UserID'
    
    $UserPassword = $ie.document.getElementsByTagName('INPUT') | 
    Where-Object {$($_.Name) -match 'password'}
    $UserPassword.value = 'password'
    
    $Submit = $ie.document.getElementsByTagName('INPUT') | 
    Where-Object {$($_.Value) -match 'SomeString'}
    $Submit.click()
    

    【讨论】:

      猜你喜欢
      • 2020-05-09
      • 2016-11-14
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      相关资源
      最近更新 更多