Powershell-我该如何处理这种类型的下拉列表 [英] Powershell - How can I deal with this type of drop down in I

查看:46
本文介绍了Powershell-我该如何处理这种类型的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 浏览到您所关注的网站
  • 填写表格
  • 在您的网站上点击发布"或提交",然后在网络活动列表中查找匹配的操作.
  • 右键单击并选择复制为->复制为PowerShell",然后以此作为自动执行表单的基础.
  • 您最终会在剪贴板中得到一个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的变数和可能出现的其他前端错误要快得多的时间来实现可行的输出.

    Screenshot

    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:

    1. Open Chrome, or the new Edge, then hit F12 to open Developer Tools, and check the box 'Preserve Log' and then the filter 'All'
    2. Browse to your site in question
    3. Fill out the form
    4. Hit 'Post' or 'Submit' on your site and look for the matching action in the network activity list.
    5. 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屋!

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