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

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.

Related

Is it possible to check for specific text to highlight on AEM site without using JavaScript?

Currently, I am building a feature in which author can decide which text to highlight throughout every single page of the site. In addition, when you hover over the highlighted text, the tooltip of the highlighted text will show the text's definition.
My idea is that the author will be given a component on a page. When the user open the component dialog, it will be given a multi-field to enter "text" and "definition" as a key-value pair. Since this data is not private, so I will render the data on a page, and use JavaScript to read data from the page and store in a dictionary. Each time you load a page, JavaScript will check for the text in dictionary and do the trick.
I am not sure if my idea is a good idea. I am concerned that the site will be very slow on mobile if I do it in JavaScript. Is there a better approach to do the trick in Java model or anywhere on server side?

AjaxControlToolkit AutoCompleteExtender: How to preserve initial text after selection

This is my first post, so be gentle :)
I am developing an ASP.NET web user control that will allow a user to type in some free text in a multi-line textbox and the application will asynchronously stem the words and use Ajax to submit them to a web service for further processing. The web service processes the words and returns a number of choices (id, title) back to the user.
Naturally, I used the AutoCompleteExtender control which basically covered all my needs but one. Once a user makes a selection from the popup window, I need to keep track of the selected item, BUT, I do NOT wish for my typed-in text to disappear or be replaced by the item selected by the user (as what AutoCompleteExtender seems to do by default).
Does this make any sense? I want the "OnClientItemSelected" event to fire (so as to know which item was selected by the user), BUT, I don't want to have to "lose" the content typed-in by the user.
Can anyone help?
Thank you for your time.
Use the DelimiterCharacters="" "" property in your extender mark-up.
Basically, what seems to happen, is that the extender will recognise a new "suggestion" after it sees your specified delimiting character. In this case, " " (a normal space.)
You can also use any other delimiter, I.e ",".

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

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).

GWT Textfield with content assist kind of functionality

I am working on a project and I have a requirement to create one GWT Textfield. User should be able to put query in the text field. But this text field should have content assist (like Ecliplse) kind of functionality.
Example: "path" is one of the predefined object in the application with having certain attribute like "name","address". So now when user type "path.", it should show available attribute. This should work almost same way as in eclipse we get while put objectname it will give all available methods to call.
Example: User writes text "From path.name, path.attribute for object.attribute"
When user writes "from","for" it will not show any assistance but when user types "path." or "object." in above statement, it should show assist.
This is an interesting idea. You could try this with a suggest box widget.
GWT Suggest Box - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwSuggestBox
GWTChosen Suggest Box - http://jdramaix.github.com/gwtchosen/
The above widget demos work with simple "contains" check on string. You would need to spend some serious logic on the regex matching if you want to pull of your idea.

How does GWT "know" which DOM element you've just selected?

It has been a while since I've touched GWT, but I was recently looking at GWT applications to see how they accomplished certain tasks. I noticed that if you go into AdWords (a GWT application), you can manipulate table information in-line. For example, if I go into my campaign and click the pencil icon next to the ad group, a little popup will appear allowing me to change the ad group's name ... except there's no identifying information anywhere in the DOM structure. No hidden fields, no id's snuck into the div elements.
What's going on here? I've been working with interactive tables, but I've always established a click handler on a class and stuck an ID in there so I can tell what I'm editing. I've always found this as unsatisfactory. Any ideas?
It uses a JavaScript variable to get a hold on the element directly when it's created. That variable can then be stored somewhere - as long as it's accessible directly or indirectly from the the global object (document), it can be retrieved later from there.
A simple pure JavaScript example would be:
document.myParagraph = document.createElement('p');
document.body.appendChild(myParagraph);
document.mySpan = document.createElement('span');
document.myParagraph.appendChild(mySpan);
...
document.mySpan.onclick = ...