简体   繁体   中英

Programmatically make clicks on a webpage

There is a onmousedown event on a webpage. I want to be able to have this event called from my app and have the WebBrowser object move to that page. How can I achieve this?

Long story short, you can't do this. This is because the javascript is a client side technology and to accomplish what javascript does on your client you're going to have to pretend to be a client: you'll need to rebuild the entire document object model and execute the javascript that way.

You can reference this ticket where I tried solving a similar issue (calling javascript from within a PHP script): Can a php proxy script call javascript functions like click?

Maybe if you explain the problem domain a little more, you'll discover that you don't even need the javascript all-together! What are you trying to accomplish and why is the javascript required? Good luck!

The WebBrowser.Document property gives you an HtmlDocument object, which has an InvokeScript method. I have used this before to execute JavaScript from a WebBrowser control. Frankly, it's an atrociously messy way to get something done, but it has worked for me. Could that be of use to you, maybe?

gnucom's right.

Perhaps not the solution you are looking for: http://watir.com/examples/
It's Ruby based and but you could have your app interact with that perhaps...

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