通过 PowerShell 填写 Web 表单无法识别输入的值 [英] Filling web form via PowerShell does not recognize the values entered

查看:63
本文介绍了通过 PowerShell 填写 Web 表单无法识别输入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 QA 工作,我需要通过网络表单填写大量申请.想法是将个人数据放在一些 xls/txt/whatever 文件中,读取该文件并使用 Powershell 将数据提供给浏览器.

Working as a QA I need to fill in a lot of applications through a web form. Idea is to have the personal data in some xls/txt/whatever file, read the file and use Powershell to feed data to the browser.

当我在 IE 中使用下面的代码填写表单时,即使它看起来工作正常,但在提交表单时却出现未输入数据的错误.

When I use the code below to fill in the form in IE, even though it seems to work fine, I get an error when submitting the form that no data was entered.

任何关于如何解决这个问题的想法或建议将不胜感激

Any ideas or suggestions how to get past this would be much appreciated

遗憾的是,我的资源仅限于 Powershell 2.0.Selenium 或任何其他更复杂"的工具至少目前是没有问题的.

Sadly my resources are limited to Powershell 2.0. Selenium or any other "more sophisticated" tools are out of question at least for now.

此处验证错误

$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("MyURL")
$ie.visible = $true

while ($ie.ReadyState -ne 4){sleep -m 100}

Function ClickById($id) {
    $ie.document.getElementById($id).Click()
}

### Základní údaje
$FnId = 'personalData.firstName'
$LnId = 'personalData.lastName'
$PhoneId = 'personalData.mobilePhone'
$EmailId = 'personalData.email'
$DataAgreementCheckBox = 'application.personalDataAgreement'
$SubmitfwdId = 'forward'


$Values = "Ublala", "Pung", "222333444", "ublala@pung.com"
$Ds1Elements = $FnId, $LnId, $PhoneId, $EmailId

$j = 0
foreach ($El in $Ds1Elements) {
    $ie.document.getElementById($El).value = $values[$j]
    $j++
}

ClickById $DataAgreementCheckBox
ClickById $SubmitfwdId

推荐答案

感谢您的建议,但它不起作用,因为表单在许多方面似乎都很愚蠢.无论如何,我在使用 SendKeys 方法时使用了你的建议作为焦点,它成功了.

Thanks for the suggestion but it did not work as the form seemes to be stupid in many ways. Anyway I used your advice for the focus when going with SendKeys method and it did the trick.

一开始我需要加载这个程序集

At the beginning I needed to load this assembly

[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")

然后相应地更改循环以使用 SendKeys 方法

and then changed the loop accordingly to use the SendKeys method

$j = 0
foreach ($El in $Ds1Elements) {
    $ie.document.getElementById($El).focus()
    [System.Windows.Forms.SendKeys]::Sendwait($values[$j]);   
    $j++
}

而且 tradaaaa 表格已填写,没有人抱怨 :)

And tradaaaa the form is filled and nobody is complaining :)

这篇关于通过 PowerShell 填写 Web 表单无法识别输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆