I am trying to click a button with Perl Mechanize, but there are some twists because I am trying to apply the same script to different sites, each of which has the same id attribute for the button, but the forms are not the same number on the page, and the buttons have no name, just an id.
Is there any way to click a button when you only know the id?
Failing that, what is the best way to determine the number of the form that holds a button with a given id?
See HTML::Form:
for my $form ($mech->forms) {
if $form->find_input('#theid') {
# this is the one
}
}
Related
Going "back" from a form doesn't take me to the previous form but back to the main form. What am I doing wrong? Here's more detail:
I have a Command that takes you from the main form of my app to a "human setup" form. From that form if you click on a certain multibutton I go to another form (MaintenanceLevel) like this:
protected void onHumanSetup_MultiButtonMaintenanceAction(Component c, ActionEvent event) {
// Invoke the next level of form
showForm("MaintenanceLevel", null);
}
In the "MaintenanceLevel" form I have an Action set to Back, but when I click the menu bar to go back I end up back on the main-form and not the "human setup" where I want to be.
Edit:
Things have got a little worse!! Now when I go back in to view the Commands for my MaintenanceLevel form it's empty: it's forgetting the command I've entered :(
Here is my command setting for MaintenanceLevel form:
You don't need to define a back command. Remove it. Codename One automatically creates back commands for you.
The usage for this option is when you create a Button and place it within the form, then you want it to behave as a back button effectively (e.g. cancel button).
What I am trying to do is really simple. Here is the code:
import re
from mechanize import Browser
br = Browser()
br.open("http://adreskodu.dask.gov.tr/" )
br.select_form( nr = 0 )
br.form.set_value(['1'],name='tip')
br.submit()
As you can see, the website first shows up with two radio buttons, and then after selecting the left radiobuttion via the br.form.set_value call and submit, I expect to access the new forms with mechanize that would appear normally if you were doing this on a browser.
What I would expect is a new form with more controls (if you go to the website and click on the left radiobutton, you will see what i am talking about).
However, I either dont do the submit correctly or don't know how to access the newly generated form that just came into being after clicking the very first radio button.
Ideally, i would want to re-find the newly created form and select the drop down menus and such. Is this a javascript issue I am encountering?
Thanks
I am writing a perl script using WWW::Selenium module to automate a website.
I am not at all a web development guy and have no idea about web technologies.
Let me try to explain the issue in layman terms.
I am dealing with a webpage, which has an order form with a button.
When I click the button, there is no page submit, but the button label changes.
Say for eg, the button goes through these changes when clicked multiple times.
Get Quote --> Order --> Confirm Order
Each time I click the button, there is no page refresh, but the button label keeps changing as above.
The id of the button is the same throughout, only the class changes.
How can I do this in WWW::Selenium?
Presently I am using wait_for_page_to_load(5000) after each click.
But the click is not having any effect on the label and I get error that timed out after 5000s.
Should I be using some other function to wait?
You could do something like this
$sel->wait_for_text_present_ok("Your text","time to wait","The message to display if this fails");
and an example below-
$sel->wait_for_text_present_ok("Order Confirmed","9000","The order was successfully placed");
Seems like you could use
$class = $sel->get_attribute($attribute_locator)
where the $attribute_locator is the button#class with button being the element locator that you clicked. Check if $class is the class you expect.
I have a form with three radio button options, and a "submit" button (no checkboxes, no text fields). Yet if a user clicks the submit button, without choosing an option, the form still submits it, picking the first option anyway. What's the best method to prevent a form from being submitted if the user DOES NOT check any of the radio buttons? (My CMS is ExpressionEngine, and this form is generated using the CartThrob extension, just FYI. But it's not a CT issue as far as I can tell.)
With jQuery you can return false if there is no value for that input.
$('form').submit( function() {
if ( !$('input:radio[name="myRadio"]').val() ) {
alert('Fix this!');
return false;
}
});
You may need to change ! to =='', but that's the idea.
I have a Grid object and added a [ (+) New Client ] button which I'd like to open a popup form to create the new client with a couple fields.
I've looked at the code examples in the website but haven't found how to do it (sorry if I've missed something).
This is the current page code:
function page_clients_listing($p){
$g = $p->add('Grid');
$g->addColumn('text','first_name');
$g->addColumn('text','last_name');
$g->addColumn('inline','telephone');
$g->addColumn('expander','comments');
$g->setSource('client');
$g->addButton('With Icon')->set('Add New Client')->setIcon('Plus');
}
Thanks in advance!
You can either create a popup or a dialog. Dialog is based on jQuery UI dialog implementation. Popups are likely to be blocked and are harder to control.
This is actually working for any object (you can apply to view, button, image, icon, etc), but I'll use button).
$b=$g->addButton('Add New Client')->setIcon('Plus');
$b->js('click')->univ()->frameURL($title,$url);
// OR
$b->js('click')->univ()->dialogURL($title,$url);
$url would most likely be returned by api->getDestinationURL(). The other page would be loaded and scripts on that page will be evaluated. Let's say you are on other page and now need to close the window.
$result = $this->addButton('Close')->js('click')->univ()->closeDialog();
closeDialog() returns a jQuery chain object pointing to a view which originally opened the frame. As a result if you do $result->hide(); then after dialog is closed, the original button ('add new client') will also be hidden.
Here is example to show some additional things you can do with frames, reloading and custom event handlers:
http://agiletoolkit.org/example/refresh1