Hack Forums
[C#] Automating Tasks in a Browser - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Automating Tasks in a Browser (/showthread.php?tid=5692175)



Automating Tasks in a Browser - mrphp - Aug 11, 2017

Hey, I'm hoping to make bots that automate tasks in a browser. I have a quite a bit of programming experience in PHP, however that wouldn't work for this type of task. I can understand the fundamentals of C#, but what should I look into if I want to create this type of thing.

Thanks,

mrphp


* - Charger - Aug 11, 2017

You can invoke a web browser control but it would be better to do web requests.


* - VouchPotato™ - Aug 11, 2017

Look into the robot framework, can't get any simpler, or search for "Selenium webdriver". Not sure if there's a C# port, but there are other tools out there. You can also play around with Jasmine/Mocha if you know javascript.

I always start people off with the robotframework.


* - Ninja - Aug 11, 2017

(Aug 11, 2017 01:53 PM)UsernameFactory Wrote:  Look into the robot framework, can't get any simpler, or search for "Selenium webdriver". Not sure if there's a C# port, but there are other tools out there. You can also play around with Jasmine/Mocha if you know javascript.

I always start people off with the robotframework.

I googled robotframework and found something related to testing.


* - hackpet - Aug 11, 2017

Depending on exactly what you want to achieve (or how "nice" do you want to do it), you have more options (i'll list only the ones i've used):

- Using the build in webbrowser and invoke actions on the elements
- Using webrequest, imitating the browser (Now i have made a Forge of Empires bot using this method)
- Use sockets for the communication (i do NOT recommend this, it's pointlessly complicated, just listed it, bc i've tried it before)

So maybe if you tell us, what you want to do, we may be able to help better.

PS.: Oh, i almost forgot, you can imitate simple user clicks and keypresses, but thats really a pain in the ass, if the form changes etc,etc... (Also, you cant do other things, bc if i know well, you can send inputs only to the active window, if this is not true, i would be happy to learn a way to do it :) )


* - mrphp - Aug 11, 2017

@hackpet and all others I'm hoping to do this with web requests. Is there anything else to know if I am planning on doing it that way?


* - hackpet - Aug 11, 2017

(Aug 11, 2017 05:04 PM)mrphp Wrote:  @hackpet and all others I'm hoping to do this with web requests. Is there anything else to know if I am planning on doing it that way?

One more tip, which may be useful. I used Fiddler to log all the communication between me and the webserver, this way i could "copy" the syntax of that.

If you need any help just feel free to ask ;)


* - Ninja - Aug 11, 2017

(Aug 11, 2017 05:04 PM)mrphp Wrote:  @hackpet and all others I'm hoping to do this with web requests. Is there anything else to know if I am planning on doing it that way?

Get a packet sniffer like Fiddler or Charles so you can sniff the HTTP requests, then emulate them using WebRequests (or WebClient (or HttpClient)). If you want to use WebRequests, I made some extension methods:
https://hackforums.net/showthread.php?tid=5530456

For WebRequests (or WebClient (or HttpClient)) you have to do session handling yourself, unlike the WebBrowser. You do this using a CookieContainer.


* - grady - Aug 11, 2017

Selenium is a very, very easy way of controlling a browser programmatically.


* - VouchPotato™ - Aug 12, 2017

(Aug 11, 2017 03:00 PM)Ninja Wrote:  I googled robotframework and found something related to testing.

That's what it was made for, but you can automate whatever you want, doesn't need to be a test automation.