简体   繁体   中英

Simulating a Mouse Click in Powershell

I already know Powershell is not really meant for GUI automation, but just the same I have a pretty large Powershell script that needs to perform a single GUI operation, that being a left mouse click. I have searched for hours and have not found a satisfactory solution. The closest I have found is an add on called Wasp, but it was written in 2009 and appears to be incomplete anyway.

Is there another add in available to solve this problem?

I cannot condone using this as a first resort, but it should work. Generally when dealing with web pages you want to use URL parameters as much as possible since webpage elements are volatile.

With that said you should be able to create an IE comobject and then select the element that way. For example:

First create an IE object:

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.navigate("YourPageURLHere.com")
$ie.visible = $true

You can manipulate certain elements by ID (ex: name="username") or even type. These can be easily found be viewing the source code of a webpage. Here are a few examples:

$Username = $ie.document.getElementByID("Username")
$Username.value = $UsernameValue

$SearchButton = $ie.Document.getElementsByTagName("button")
$SearchButton.click()

Even if the webpage changes, since we have it all attached to the IE object you can then grab the output elements that generate after the submit button is clicked and feed them back into your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM