none
Need to create a mouse click event in powershell

    Question

  • Hello, I've just started using powershell. I have written an automation script that works perfectly with the exception on one step.
    I’m creating a batch of records in an in-house web application with my script. Using internet explorer I’m entering data in fields and clicking the next button to advance. On one page there is date that needs filled in but it is validated by some client side JavaScript; which is invoked when the "next" button is clicked. The problem is when I call the .click() method through powershell the JavaScript is not invoked. When you manually click on it with the mouse pointer it works fine. I've done a lot of testing and I think the easiest way to get around is to move the mouse pointer to the position of the button with:


    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(613,664)

    then invoke a click event with the mouse pointer. But I can’t find any documentation on how to create a click event.
    Thanks!!

     

    • Edited by basspenguin Friday, January 08, 2010 6:53 PM spelling
    Friday, January 08, 2010 6:53 PM

Answers

  • Here's a great article on UI automation with Powershell.  They use user32.dll functions to do things.  You could do the same thing, and then use the mouse_event function to perform the click.  Of course you would need to write a cmdlet to do this in C# unless someone knows a way to import a non-.net dll and function into Powershell natively.  I don't believe you can perform a mouse click natively with .net.
    Saturday, January 09, 2010 2:53 PM
  • Hi,

    i also plan to have a deeper look in testautomation with Powershell.

    What i found so far and i think its worh to have a deeper look:

    WASP - http://www.codeplex.com/WASP
    WatiN  - http://watin.sourceforge.net/

    regards
    Tom
    Saturday, January 09, 2010 7:44 PM

All replies

  • Here's a great article on UI automation with Powershell.  They use user32.dll functions to do things.  You could do the same thing, and then use the mouse_event function to perform the click.  Of course you would need to write a cmdlet to do this in C# unless someone knows a way to import a non-.net dll and function into Powershell natively.  I don't believe you can perform a mouse click natively with .net.
    Saturday, January 09, 2010 2:53 PM
  • Hi,

    i also plan to have a deeper look in testautomation with Powershell.

    What i found so far and i think its worh to have a deeper look:

    WASP - http://www.codeplex.com/WASP
    WatiN  - http://watin.sourceforge.net/

    regards
    Tom
    Saturday, January 09, 2010 7:44 PM
  • I couldn't get to the WASP page from that url, but I was able to from this one: http://wasp.codeplex.com/

    That WASP is pretty cool.  It has a send-click cmdlet.  I'm going to have to play with that.  Thanks for the link.
    Saturday, January 09, 2010 8:30 PM
  • Hey thanks for the great links. As it turns out the solution to my problem was I needed to insert a delay after I called .click() to allow the client side JavaScript to finish. But these links look like great resources.

    Monday, January 25, 2010 4:47 PM
  • I am trying to automate some of my support groups roles, could you please send me the code or a good direction in where to get this at. Please any good advice would be appreciated.
    Monday, August 05, 2013 8:48 PM
  • I am trying to automate some of my support groups roles, could you please send me the code or a good direction in where to get this at. Please any good advice would be appreciated.

    i would post another question this one is marked answered and its old so not many people are going to see this
    Monday, August 05, 2013 8:56 PM
  • Hi,

    You should start a new thread, this one has been answered for almost 4 years.


    Don't retire TechNet!

    Monday, August 05, 2013 8:56 PM
  • I really need to see the code to understand it and try to write my own around it
    Tuesday, August 06, 2013 5:55 PM
  • I really need to see the code to understand it and try to write my own around it

    Well, considering that the OP has zero activity details in his/her profile, I'd say you're going to have to start from scratch.

    Don't retire TechNet!

    Tuesday, August 06, 2013 5:58 PM
  • yea i see...I really need it to but thanks a lot 

    Tuesday, August 06, 2013 6:09 PM