web submission automation: simulate onclick event on a title element to load form - forms

A resume-service I use requires that for each listed activity on the resume, there is an hours-per-week field and total hours field. However, the total hours field does not update itself automatically no matter how many weeks pass. My goal is to write a script that does this.
The idea behind the script is:
Log in to website -> go to a certain page -> submit a form** on that page updating the total hours
**unfortunately, for the form to open, you need to click an "edit" title element first which causes it to show up. I've taken a look at the html of the webpage but cannot find the form or input tags corresponding to the form I wish to submit, only that the form is generated with what I think is a javascript function call from the element's onclick field.
I believe the relevant html snippet is:
<a title="edit" class="edit" href="#entry-type" onclick="editComponent('10227041','education');">Edit</a>
but just in case there is a much larger code snippet later in this post (check the 2nd pastebin link at the bottom)
THE QUESTION: Is there a specific language/library/way (preferably in python, although I can work with Java) to simulate an onclick event and that would result in a form loading?
I've worked on this problem a bit, starting with python's mechanize library. I wrote two functions,
def login(br,url):...
def navigate(br,baseurl,url):...
which would satisfy the first two parts of my script's plan, but the third is where the trouble starts. When I print all the forms on the page using
for form in br.forms():
print form
I get http://pastebin.com/Gxy2tc1A
The website's html can be found on http://pastebin.com/PySri5cb
Later I tried to work with Selenium (the firefox IDE plugin) and then exporting code into python, where I would edit it to satisfy my specific needs, but that was a no-go either due to some awkward errors.

Have you looked into GreaseMonkey? You should be able to use that to extract the hours per week, do the math and populate the total hours field. You could probably do the entire thing. Anything that can be done on the page in JavaScript could be done within GreaseMonkey.
EDIT: The code for that site is awful. I especially like the inline call to loadResume() that is made BEFORE the element it writes to (#build-wrap).

Related

Editing a custom object record in visualforce page

How can I achieve editing a custom object record by listing all the records and selecting a particular record in checkbox which will open popup window for editing purpose in visualforce ?
What have you tried already, do you have any code sample you're stuck with?
Be careful what you wish for, "all records" when it's tens of thousands of them will likely blow the page's viewstate. I mean solution might be as simple as making a page with <apex:enhancedList> in it...
Read up about StandardSetController.
It's old feature, it's battle-tested, there will be tons of examples how to use it like https://developer.secure.force.com/cookbook/recipe/editing-multiple-records-using-a-visualforce-list-controller or http://www.sfdcpoint.com/salesforce/pagination-using-standard-set-controller-salesforce/
Looks like you need something very simple that just displays list of links & these links will have JavaScript (window.open function?) that creates a popup with record id passed.

AEM: Access component rendition only, not the whole page containing it

I have a component that performs pagination with its suffix.
So,
/contents/myproject/search.html/1 brings the first page displaying 10 results
/contents/myproject/search.html/2 brings the second page displaying 10 different results
Now I've been asked to make it more dynamic and add a next button to page 1, so it will append the next 10 results, instead of having another separate page load.
My plan is to use JS and make an AJAX call to the following page, find the div I want, take those 10 results and append them to my first 10. The issue is that page is enormous and I would be downloading a lot of other unnecessary stuff in that call.
Is it possible to access the rendered component only? the one being added by
<cq:include path="pagination" resourceType="myproject/components/pagination" />
If you have node pagination under /contents/myproject/search/jcr:content with correct sling:resourceType, then it should be pretty easy - GET request to /contents/myproject/search/jcr:content/pagination.html.
Also it highly depends on implementation of this component if suffix will work there.

How can I select a value matching my input from a TypeAhead control using WWW::Mechanize?

So ordinarily the element I want to pick from a list would be populated on a page and I'd just find it and pick it. But I'm dealing with a control that doesn't populate list elements until some input has been stuck into a text box, after which it gives me a list of recommendations.
For an example of the kind of list I'm talking about think of Facebook's "People, Places, and Things" search field.
I want to plug a string into this text box, select the same string from the list of recommendations, and submit the form. The issue I'm having right now is I can't seem to get Mechanize to even recognize the field is there. I examine a dump of $mech->find_all_inputs and it isn't listed. Is this kind of field just beyond Mechanize's jurisdiction?
This control's magic comes via Javascript, and (as you know) WWW::Mechanize don't work with Javascript.
But you can find (with Firefox's HTTPFox extension for example) what request your browser sends to the target site than you get "recommendations" and make the same request (I'm sure this is POST) from your WWW::Mechanize object.

Dojo Form Submit Woes

So here's the problem. We have some big dojo forms created using Zend_Dojo_Form. The problem is that validation, while working per element, does not work on any of the submit buttons. Due to the inflexibility of the standard layouts, we're compelled to use viewscripts.
I thought I had the whole thing working fine, that was until I needed to make sure that when you went from page to page of the multipage form using the quick links that it submitted the current page (with validation.)
I noticed that when I force-fired the click event on the submit button, no validation was occurring (or rather, there was no preventing the form submission if there were invalid values. Those values just were not submitted.)
So I looked at some tutorials where I found that the form is validated by calling
dijit.byId('form-id').validate();
or the shortcut I was looking for, primarily (originally)
dijit.byId('form-id').submit();
Neither of which are functions, since the byId is returning undefined. What this means is our viewscript - or whatever the whole process is - generating dojo forms with Zend is partly voodoo anyway - does not actually generate the dojo form dijit.
So how does one do this in a viewscript? As in, what sort of php calls or attribs does one attach to the form tag to get it to be interpreted by Dojo to be the basis for a form dijit?
Here is the code from the viewscript:
<form action="<?= $this->escape($this->element->getAction()) ?>"
method="<?= $this->escape($this->element->getMethod()) ?>"
id="case-record-form">
This sounds very similar to a problem I had. If I rendered the form by echoing it, validation worked, but when using a viewscript it would not. I discovered that when using a viewscript, Zend does not add the form to its zendDijits array, so you have to do it manually.
Add something like:
$script = 'zendDijits.push({"id":"MyFormId","params":{"dojoType":"dijit.form.Form"}})';
$this->headScript()->appendScript($script);
at the top of the viewscript.

Go to a new page, but still have GWT variables?

In GWT, I would like to do something like a form submission that takes me to a new page, with new style sheet and new static elements, and when I get there, be able to extract the values of GWT variables still in GWT. In other words, I want to do most of the form processing on the client side instead of sending it to a servlet to be processed and sent back. Is that possible? Would FormPanel allow me to do that? How do I access the contents of the form fields in GWT on the new page?
I'm not sure I'm getting the right picture here, but I see several possibilities:
Pass the variables in the url like example.com/myform#create/param1/param2 or any other format you want, then read it using the History class
Use something like this - create an iframe from GWT (maybe put it in Lightbox or something similar), populate it the way you want using the current state of the app, and when the user is finished, he'll just close the (Lightbox) frame and get back to the main application
You could also pass around data in a "hidden" way (no visible data in the url or even through POST) using the window.name hack - there's even a sample implementation for GWT to get you started
ATM, I prefer the second option, since it goes best with the whole no refresh, same page, one app, GWT thing :) That is, unless I'm getting the wrong picture and you want to do something else.
GWT is really meant to be used for the whole application, where "pages" are replaced by application state and URL fragments, and "form submission" is replaced by AJAX calls.
If you want to validate form fields, this can easily be done with regular JS or a library like jQuery.
I'm not sure it I get you right either, but for what I'm receiving, having a new page to process the form is not the optimal design. The reason been that you might have to write different GWT app for that which mean overheads, and creating new window (or tab) will move the user's attention away from where they are. Why not using another page WITHIN gwt to process the form with tab panel or hidden panel?