Example of how to execute JavaScript in PowerShell _powershell

Source: Internet
Author: User
Tags mongodb postgresql redis

Background and problems

Someone wrote a Web application that uses the ASP.net forms technology. It uses a DropDownList control, the user selects an item, the page will return, and then the next dynamic display another control, logic is very simple.



This is the generated part of the HTML source code:


 code as follows:

<select name= "Eventtypedropdown" id= eventtypedropdown "onchange=" javascript:settimeout (' __doPostBack ' Eventtypedropdown\ ', \ ' \ ') ', 0 ' >
<option value= "Exception" selected= "selected" >Exception</option>
<option value= "Memory" >Memory</option>
<option value= "Perf" >Perf</option>
</select>

Luckily, the control has an ID. The PowerShell script I wrote is as follows:







 code as follows:

$ie = new-object-com "Internetexplorer.application"
$eventType = $ie. document.getElementById (' Eventtypedropdown ')
$eventType. selectedindex=1

After the script runs, the down list on the page selects memory, but the following dynamic controls are not displayed because the page does not return.





Tangled up in me all afternoon. Please don't tell me this time, I can use other test framework, test tools. Here, do not want to introduce other tall things, just want to use IE itself to solve this problem.



Solution


I subconsciously open the F12 Development Debugging tool, the onchange event JavaScript code copied into the console, run, the page began to refresh, the following dynamic control loaded out. At this time saw a ray of dawn. That is, the question: executing JavaScript in IE ComObject can solve this problem. How do you do that?


code as follows:

$ie. Document.parentWindow.execScript (' javascript:settimeout ' __dopostback (\ ' eventtypedropdown\ ', \ ') ', 0) ', ' "







Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.