Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-24-2012, 12:35 PM   #1
Registered: Apr 2009
Location: Pakistan
Distribution: Fedora 9
Posts: 192

Rep: Reputation: 30
Question How to trigger a javascript in HTML file through a bash script?

Hello there,

I need to write a shell script that triggers a javascript embedded in a separate HTML file. Please help me.

Best Regards
Old 04-25-2012, 07:51 AM   #2
Registered: Feb 2001
Location: South Africa
Distribution: Fedora, Mandriva, PCLOS, SUSE - anything a can get my hands on
Posts: 140

Rep: Reputation: 15
View the html source, get the javascript and run it in the shell script.
Old 04-26-2012, 10:20 AM   #3
Registered: Apr 2009
Location: Pakistan
Distribution: Fedora 9
Posts: 192

Original Poster
Rep: Reputation: 30
Thanks FNC, I do appreciate you response.
Here, in fact, I need to provide the scenario.
I have an HTML page, sections of which are :


function validat() 
	if ("" ||"0" ||"1") 
		alert("Please enter your Roll No.");
		return false;
	{       return true;   	}
<form name="form1" method="post" action="Result.asp" onSubmit="return validat();">
<input name="RollNo" type="text" id="RollNo">
<input name="Submit" type="submit" value=" Search ">
Clearly, the page:
  • has an input text field (for RollNo) and a 'search' button
  • when 'search' button is clicked validate() javascript is triggered.
  • If the input (RollNo) was not empty, neither a zero nor a one, then this input is passed to Result.asp (serverside script)
  • Result.asp returns a page containing Result of the RollNo passed to it.

What I want

I have to get the results of many or all. I know range of RollNos (suppose from 1 to 100). Doing this manually will be hard. I want to automate the process through a bash script in Linux.
Here is my approach for this:

In a shell script run a loop from i=1 to 1=100
For each 'i' do this:
  • Change:
    <input name="RollNo" type="text" id="RollNo"> to <input name="RollNo" value = "i" type="text" id="RollNo">
    [value attribute is added with RollNo]
  • Trigger validate() script to submit the form.
  • Use wget (or something like that) to save downloaded page (that contains result) in temp.html
  • Use awk (or something like that) to append the result to AllResults.txt
  • Change i to i+1

My problem is how to trigger this validate() script, that in a separate HTML file through a bash script.

Best Regards

Last edited by mq15; 04-26-2012 at 10:21 AM.
Old 04-26-2012, 05:51 PM   #4
Senior Member
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,849
Blog Entries: 36

Rep: Reputation: 455Reputation: 455Reputation: 455Reputation: 455Reputation: 455
Sounds to me like you want to "emulate" a fully functioning web browser and automate the "driving of input". As far as I know the only way you can do that is by using an actual browser which renders the DOM for a user to see. To automate that you would need something to automate controlling a real browser such as selenium-rc.

There are JS interpreters and library bindings out there such as the JavaScript module for Perl and the python-spidermonkey library for Python. But they are both bindings for SpiderMonkey and only run pure JS which isn't accessing DOM.

What you want to do can't be accomplished simply in a shell language like bash. You need to turn to more powerful languages such as Python or Perl to accomplish it. And in your case, an actual browser to automate. If you're attempting to do something like this in a headless environment then I don't believe it can be done with currently existing tools, not that I've seen anyway. If you figure it out how to do it headless then I'd be interested in seeing how you go about it.

Another way to go about it would be to access the submission URL with all possible valid inputs from the web form and analyze the return code or html output. This way you avoid the JavaScript. If the submission returns a proper http response code (i.e. 200 for success) then something like curl can be used in a bash script with the test utility. However if you have to interpret the HTML on the other end then you'll need to turn to something more powerful like Python or Perl. That's assuming you can build the URL yourself without requiring a session ID. Or on the server side make yourself a fake, valid, session ID in which you can test input. In that case I am assuming you're testing an application you wrote, or have access to the developers for the testing.


Last edited by sag47; 04-26-2012 at 06:00 PM.
Old 04-27-2012, 12:58 PM   #5
Registered: Apr 2009
Location: Pakistan
Distribution: Fedora 9
Posts: 192

Original Poster
Rep: Reputation: 30
Okay. Thanks a lot sag47.
Now while I am testing selenium-rc, how much time it will take to get hands on it, is there any other suggestion by someone else ??

Best regards.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script similar to javascript var.substring(start,end) piman Programming 3 09-02-2011 09:17 PM
[SOLVED] bash script to dynamically edit an html file melee Programming 24 04-17-2010 01:53 PM
Trigger bash script when screen saver starts of desktop gets locked BinWondrin Programming 4 08-01-2008 03:40 AM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 07:53 AM
Can I get an incoming email to trigger a script file? davee Linux - General 2 10-16-2003 02:45 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration