I want to create a script to do certain actions on a web page on a schedule. I know there are browser extensions such as Greasemonkey or Selenium that I can use but my requirement is that the script should run from a command prompt. My preferences are PowerShell and NodeJS, or any .NET solution. One thing I was wondering was is it possible to record some web interaction in a .HAR file and then execute it, or is the .HAR format only used for logging network traffic and cannot be re-run? Thanks!
2 Answers
I've never seen a tool to execute a .HAR file directly, although there is enough information in a HAR file that you could write a tool to parse it and replay some of the requests.
The approach I would use, however, is to either write a shell script that executes cURL commands that perform the actions you need (in Chrome you can get a cURL command for a request from the network tab of the developer tools), or if the interaction is too complex, try writing a PhantomJS script that can do what you need.

- 129
- 1
- 5
If you are not limited by the browser type I think that the PowerShell is the best choice.
It covers all your requirements, like
create a script to do certain actions on a web page on a schedule.
and
the script should run from a command prompt.
and its a
.NET solution.
Since it is developed for task automation and configuration management. Consisting of a command-line shell and associated scripting language built on the .NET Framework. Also provides full access to both local and remote systems and network devices.
I have such scripts in these my articles - custom script #1 and custom script #2.
The Windows Task schedular will manage the launch of your scripts at pre-defined times or after specified time intervals.
Update
About the jQuery injection in PowerShell script you can try one of these:

- 6,880
- 3
- 29
- 47
-
Yup, that's what I ended up doing. However, I have trouble running JQuery on the page. I created these questions for it: [(1)](http://stackoverflow.com/q/26021813/450913) [(2)](http://stackoverflow.com/q/26023915/450913) – orad Sep 24 '14 at 20:54
-
I couldn't do it by self too back then, so I just had to use the JS support of IE COM. However please see my updated answer, maybe it will be helpful to you. – ekostadinov Sep 25 '14 at 10:10
-
Thanks. Also see my solution here for running JavaScript/jQuery in PowerShell and receive results back from the web page: http://stackoverflow.com/a/26046039/450913 – orad Sep 25 '14 at 20:26
-
Link in "custom script #1", "custom script #2" are broken so are "post #1", "post #2" and "post #3". Requesting @ekostadinov to update the hyperlinks to keep the answer helpful. – Siva Senthil Jul 07 '17 at 08:38