【问题标题】:Powershell IE Automation- Can't Set value for Text areaPowershell IE 自动化 - 无法为文本区域设置值
【发布时间】:2020-07-10 12:41:43
【问题描述】:

我正在查看一个带有 textarea 的网页:

<textarea aria-label="Add comment" class="form-control" cols="0" maxlength="100000" name="text" rows="0" tabindex="0" aria-required="true"></textarea>

我想设置 textaea 的值,但是这样做我得到了错误:-

Error Details - Exception setting "value": "The property 'value' cannot be found on this object. Verify that the property exists and can be set.

谁能帮我设置textarea的值。

我正在使用下面的代码来设置 textarea 的值。

 $AddCommentBtn = $ie.document.getElementsByTagName("section") | where {$_.className -eq "modal fade modal-addnote in"}
    $textareavalue=$AddCommentBtn.getElementsByTagName('textarea')

$textareavalue.value='Test'

下面是我的脚本:-

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible

$username=""

$password=""

$ie.Navigate("to some web-page")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$usernamefield = $ie.document.getElementByID('Username')
$usernamefield.value = "$username"

$passwordfield = $ie.document.getElementByID('Password')
$passwordfield.value = "$password"

$Link = $ie.document.getElementByID('submit-signin-local')
$Link.click()

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$ie.Navigate("to some form")
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 10;}

$description = 'Test Description'
$descriptionfield = $ie.document.getElementByID('description')
$descriptionfield.value = "$description"

$AddCommentBtn = $ie.document.getElementsByTagName("section") | where {$_.className -eq "modal fade modal-addnote in"}
$textareavalue=$AddCommentBtn.getElementsByTagName('textarea')
$textareavalue.value='Test'

#InsertButton
$Link = $ie.document.getElementByID('InsertButton')
$Link.click()
$ie.Quit()

提前致谢。

【问题讨论】:

  • 请展示您如何将 XML 转换为 PowerShell 对象。对我来说,它最初看起来有点像 Javascript。
  • 看起来你的 $textareavalue 变量没有得到任何东西。不幸的是,您没有显示足够的 HTML 来帮助您。此外,getElementsByTagName 可以返回一个 textarea 元素的数组,而不仅仅是一个..
  • 您好,已更新我的脚本代码。请帮忙
  • @Theo $textareavalue 确实具有值,因为在我的表单中只有一个 textarea,因此由 getElementsByTagName 返回

标签: powershell textarea ie-automation


【解决方案1】:

我已经通过在设置 textarea 的值之前添加 focus() 自行解决了这个问题。

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多