2

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?

5
  • What exactly is the action? Can it be accomplished with keystrokes? Commented Mar 11, 2016 at 22:07
  • I do not think so, I need to click on a button in a web page. There is no key shortcut for this particular button. Commented Mar 11, 2016 at 22:28
  • I've used Wasp before and it worked fine in my experience. Commented Mar 12, 2016 at 0:26
  • To dfundako's point, you can potentially still automate with keystrokes by using TABs. Try bringing up the GUI you intend to automate and hit tab and see if the button is in the tab order. If it gets the focus I think hitting spacebar will click the button. EDIT In fact I performed Save Edits on this comment by pressing TAB, then SPACE. Commented Mar 12, 2016 at 0:28
  • Clicking a button on a webpage typically means sending an HTTP POST request and it can be emulated without resorting to GUI automation. I recommend using a debugging proxy such as Fiddler to find out what exactly happens when you click that button. Commented Mar 12, 2016 at 12:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.