Javascript to automate button click

I need javascript that clicks the button on a form.

I dont have direct url. But to get to the form, please click "Apply now" on the page http://www.indeed.com/viewjob?cmp=TELES-PROPERTIES&t=Real+Estate+Assistant&jk=8e0bc33c6838aac9&q=%2440%2C000

It takes you to a form which has the continue button. I want to automate clicking the 'Continue' button.

document.forms.item(0).submit() acts weird. This is an iframe with in iframe. Can you help?

Note: This is being done for personal work automation
pritipatel0408Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You can't - your page / iframe relationship violates the same origin policy. Although the base domain is the same your IFrame's src is https://apply.indeed.com and your main page is http://www.indeed.com - differs on sub-domain and protocol.

http://javascript.info/tutorial/same-origin-security-policy

Your main page scripts are therefore going to be denied access to the inner iframes.

The only solution is to put script into your apply.indeed.com pages to call into the parent.
0
pritipatel0408Author Commented:
Thank you. I am new to javascript world. Can you provide the script that I put into apply.indeed.com to make this work?
0
Julian HansenCommented:
I cannot test properly but it would be something like this

This would go inside the first iframe
// GET THE URL FOR THE CONTAINER - YOUR MAIN PAGE
// BECAUSE OF THE SECURITY RESTRICTIONS WE CAN GET THE
// REFERRER (THE PARENT) BUT NOT ACCESS THE hostname AND
// OTHER MEMBERS OF THE PARENT'S LOCATION.
// WE USE A TRICK BY CREATING AN <a> ELEMENT AND SETTING
// ITS href TO THE REFERRER URL WE CAN THEN EASILY ACCESS
// THE COMPONENTS OF THE URL. IN THIS CASE WE ARE AFTER
// THE hostname

var parenturl = document.createElement('a');
parenturl.href = document.referrer;

// CHECK TO SEE IF THE hostname OF THE PARENT URL IS www.indeed.com
// IF IT IS THEN WE WANT TO SUBMIT THE FORM
if (parenturl.hostname == 'www.indeed.com') {
 
  // GET THE FIRST iframe IN THIS PAGE
  var ifr = window.frames[0];

  // GET THE FORM BY ITS ID
  var frm = ifr.document.getElementById('apply_form');

  // SUBMIT IT
  frm.submit();
}

Open in new window


NB: I tested this in the console window and it seems to work - however the form does not submit - it returns to the same page. This can be replicated by clicking on the button. Therefore I am not certain that I have fully understood your requirement.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pritipatel0408Author Commented:
Thank you Julian. I shall be awarding the points for the above solution. However, I cant get the above script working yet. Please let me know if you would rather want this posted as separate question.

I have been using chrome's autofill extension http://www.tohodo.com/autofill/help-chrome.html to achieve the button click automation. You can specify a javascript in autofill (please see attachment) that would automatically run on a page you open. Would you kindly take a stab at autofill to automate the button click for me?  Please let me know if I need any more clarifications.

Sorry. I dont fully understand when you mean the form does not submit. Perhaps form returns to same page when its incomplete?

Many many thanks!! Really appreciate your hard work.
autofill.png
0
Julian HansenCommented:
Sorry. I dont fully understand when you mean the form does not submit. Perhaps form returns to same page when its incomplete?
Yes

I was not aware you were using auto complete

Try adding
cd(frames[1]);
// GET THE URL FOR THE CONTAINER - YOUR MAIN PAGE
// BECAUSE OF THE SECURITY RESTRICTIONS WE CAN GET THE
// REFERRER (THE PARENT) BUT NOT ACCESS THE hostname AND
// OTHER MEMBERS OF THE PARENT'S LOCATION.
// WE USE A TRICK BY CREATING AN <a> ELEMENT AND SETTING
// ITS href TO THE REFERRER URL WE CAN THEN EASILY ACCESS
// THE COMPONENTS OF THE URL. IN THIS CASE WE ARE AFTER
// THE hostname

var parenturl = document.createElement('a');
parenturl.href = document.referrer;

// CHECK TO SEE IF THE hostname OF THE PARENT URL IS www.indeed.com
// IF IT IS THEN WE WANT TO SUBMIT THE FORM
if (parenturl.hostname == 'www.indeed.com') {
 
  // GET THE FIRST iframe IN THIS PAGE
  var ifr = window.frames[0];

  // GET THE FORM BY ITS ID
  var frm = ifr.document.getElementById('apply_form');

  // SUBMIT IT
  frm.submit();
}

Open in new window

To the script I posted earlier so it looks like this
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pritipatel0408Author Commented:
We are almost there. The snippet worked great for the original link I provided. But for the following link, I dont have luck. Its puzzling given form ID and element info remain the same.  

http://www.indeed.com/cmp/Independent-Capital-Management,-Inc./jobs/Financial-Advisor-Management-Trainee-3075d86ff75e64f2?sjdu=QwrRXKrqZ3CNX5W-O9jEvWZePZcXeI16EUz3N-7_glvdMgXNrH7iSjZbyjCI-ynra3sLgM25MQBcowli_0HyIqI2sOFSgYxOKZmx55Z5rJ4 

Any idea where I could be going wrong ? Many thanks! This helps me with saving lot of hassle filling my job applications.

I have moved this into another question
http://www.experts-exchange.com/questions/28698758/Javascript-to-automate-button-click-Part-II.html
0
Julian HansenCommented:
I tried running the script on that page and it seems to work. Are you still having issues with this?
0
pritipatel0408Author Commented:
I'm working in chrome and command cd() is not supported. Can you please make a script available that  does not use cd?
http://stackoverflow.com/questions/5712187/how-do-i-cd-into-an-iframe-in-chrome-developer-tools-or-firebug-lite-in-chrome
0
Julian HansenCommented:
I think this is where the solution trips up. Chrome does not support the cd command and because of the different origins restriction it is not possible to access in the inner iframes through script.

The code would have to be placed in the actual page source that is loaded into the iframe.
0
pritipatel0408Author Commented:
This is sad. Can we not work around using contentWindow  like the link mentioned (http://stackoverflow.com/questions/5712187/how-do-i-cd-into-an-iframe-in-chrome-developer-tools-or-firebug-lite-in-chrome) ?
EDIT: contentWindow does not work for cross origin case.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.