Powershell-我该如何处理这种类型的下拉列表 [英] Powershell - How can I deal with this type of drop down in I
问题描述
您最终会在剪贴板中得到一个PowerShell cmd,可以将其修剪成类似这样的内容,这是进一步自动化的一个很好的起点.
Invoke-WebRequest -Uri"https://api.weather.com/v3/location/search?apiKey=6532d6454b8aa370768e63d6ba5a832e&language=zh-CN&query=90210&locationType=city%2Cairport%2CpostCode%2Cpws& format = json`-标题@ {方法" ="GET""authority" ="api.weather.com"方案" ="https""path" ="/v3/location/search?apiKey = 6532d6454b8aa370768e63d6ba5a832e& language = zh-CN& query = 90210& locationType = city%2Cairport%2CpostCode%2Cpws& format = json""accept" ="application/json,text/plain,*/*""origin" ="https://www.wunderground.com""accept-encoding" ="gzip,deflate,br""accept-language" ="zh-CN,en; q = 0.9""dnt" ="1"}
这是我们在我工作的大银行中大规模测试Web应用程序的一部分.
为什么使用这种方法?
通过这种方法,您正在测试站点上实际的网络交互,而不是填写IE窗口并提交.一般而言,采用这种方法要容易得多,并且比处理JavaScript jQuery Validing的变数和可能出现的其他前端错误要快得多的时间来实现可行的输出.
How can I automate powershell to select the Company fro this type of dropdown because it's not a normal drop down but it shows values only once you start typing?
For e.g. in this case when I type C it shows Company. Refer the screenshot image above.
Following code inserts the value but it doesn't recognize it and gives an error asking to input value -
$test.document.getElementById("val1").value = "Company (Company)"
Below code which works for normal drop-downs doesn't work here -
$val = $test.getElementById("val1")
$val[1].selected = $True
$val.FireEvent('onchange') > $null
An easier way to do this would be to skip automating an Internet Explorer window in its entirety, and instead simple capture the network operation and perform that in your scripts.
It's covered in detail in this blog post 'Faster Web Cmdlet Design using Chrome 65' (written by me) but to summarize:
- Open Chrome, or the new Edge, then hit F12 to open Developer Tools, and check the box 'Preserve Log' and then the filter 'All'
- Browse to your site in question
- Fill out the form
- Hit 'Post' or 'Submit' on your site and look for the matching action in the network activity list.
- Right-click and choose 'Copy As->Copy as PowerShell' and then use this as the basis for automating the form.
You'll end up with a PowerShell cmd in your clipboard that can be trimmed down to something like this, and is a great launching point for further automation.
Invoke-WebRequest -Uri "https://api.weather.com/v3/location/search?apiKey=6532d6454b8aa370768e63d6ba5a832e&language=en-US&query=90210&locationType=city%2Cairport%2CpostCode%2Cpws&format=json" `
-Headers @{
"method"="GET"
"authority"="api.weather.com"
"scheme"="https"
"path"="/v3/location/search?apiKey=6532d6454b8aa370768e63d6ba5a832e&language=en-US&query=90210&locationType=city%2Cairport%2CpostCode%2Cpws&format=json"
"accept"="application/json, text/plain, */*"
"origin"="https://www.wunderground.com"
"accept-encoding"="gzip, deflate, br"
"accept-language"="en-US,en;q=0.9"
"dnt"="1"
}
This is part of how we test web applications at scale at the big bank where I work.
Why use this approach?
In this approach, you're testing the actual network interaction on the site, rather than filling out a IE Window and submitting it. It's generally dramatically easier to go this route, and will have a quicker time to viable output than dealing with the vagaries of JavaScript jQuery Validation and other front-end errors that can crop up.
这篇关于Powershell-我该如何处理这种类型的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!