【问题标题】:Powershell IE Automation- Can't specify textbox by ID or TagNamePowershell IE 自动化 - 无法通过 ID 或 TagName 指定文本框
【发布时间】:2020-07-07 12:28:18
【问题描述】:

我正在尝试使用 powershell 在两个文本框中输入文本。我可以在第一个框中输入一个值,但不能在第二个框中输入值。这是因为我不知道如何隔离第二个文本框,因为它与第一个文本框具有相同的代码,包括 ID、类、标记名等。

下面是我的代码,其中的 URL 被取出(由于工作)。我最初想通过在第一个文本框的值上使用 -ne 来隔离第二个文本框,因为通过输入一个值来区分代码,但这似乎不起作用。我是编码新手,所以如果我表达自己不好,我深表歉意,但您可以提供的任何帮助将不胜感激。

Here are two text boxes, I can enter a value into the first one using powershell but I am unable to isolate the second text box to enter a value into it. This is due to the two lines of code being identical- See second image

As you can see the two lines of code for input are identical and as such I cannot use GetElementById/TagName/Name to identify which text box I want powershell to enter the value into.

$Web = "URL"
$Internet = New-Object -ComObject InternetExplorer.Application
$Internet.visible = $true
$Internet.Navigate($web)

While($Internet.Busy -eq $true){
Start-Sleep -Seconds 1
}

$Internet.document.getElementById("filterValue").value="Number"
$link = $Internet.Document.getElementsByTagName('a') | where-object {$_.innerText -eq 'Next Prompt'}
$link.click()

While($Internet.Busy -eq $true){
Start-Sleep -Seconds 1
}
**#Question about coding starts here**

$Input = $Internet.Document.IHTMLDocument3_getElementById("filterValue") 
$Input.value = "1/1/2020"

While($Internet.Busy -eq $true){
Start-Sleep -Seconds 1
}

$Input2 = $Internet.Document.IHTMLDocument3_getElementById("filterValue") | ? {$_.value -ne "1/1/2020"}
Start-Sleep -Seconds 4 
$Input2.value = "1/2/2020"

【问题讨论】:

    标签: powershell internet-explorer automation


    【解决方案1】:

    我检查了 HTML 代码的图像,看起来 HTML 代码存在一些问题。

    1. HTML 元素的 ID 应该是唯一的。这意味着在一个网页上不能有多个具有相同 ID 的元素。

    2. 我还注意到输入元素的末尾有 / 用于关闭它。之后还有 2 个关闭输入标签。在 HTML 中,Input 元素没有结束标记。所以这是无效的 HTML 代码。

    3. 验证并确认您指的是这 2 个文本框的正确代码。尝试使用开发人员工具查看这 2 个文本框的 HTML。

    我建议你联系网站的开发者并告知他们这个问题。

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 2013-01-21
      相关资源
      最近更新 更多