not able to click a button in www::mechanize perl - perl

after i filled a certain form, im trying to click this button
<input class="proceed" type="button" name="new_proceed" value="Create">
, when i tried
$mech->click_button(name=>"new_proceed");
it gives me an error telling me there's no clickable object with this name. and when used
$mech->click_button(value=>"Create");
i get can't call method "header" on an undefined value at C:/strawberry/perl/site/lib/WWW/Mechanize.pm line 2467.
So whats wrong? Thanks

<input class="proceed" type="button" name="new_proceed" value="Create">
Since it is of type button, it doesn't do anything in HTML (it is usually used as something to bind JavaScript to, which WWW::Mechanize doesn't support).
Look to something that supports JS such as WWW::Mechanize::Firefox instead.

Try $mech->click_button(name=>"new_proceed");

try using HTML::Forms.. U can get the form info from the view source and you can click the button .. Another option is $mech->request .. u can create a request using make_request once u r done with filling up the form and then use $mech->request

Related

Play! Framework (2.6.2) passing route with type Call to custom view

I have a question about passing a play.api.mvc Call parameter from one .scala.html file to another. The basic idea of the view I want to create is a reusable confirmation dialog that shows up on different actions, and different screens. So being able to pass a Call parameter that gets executed when the user clicks Yes.
Here is the code I am using in my customConfirm.scala.html view:
#(call: Call)
<div>
<div> Are you sure ? </div>
Yes
<div> No </div>
</div>
And this is the code where I am calling it:
#views.html.partials._customConfirm(#routes.HomeController.welcome())
This last peace of code gives me a compilation error:
illegal start of simple expression
Am I missing something, or is this method a completely wrong way of going about it? Any help would be greatly appreciated!
Omit the # when calling the reverse router:
#views.html.partials._customConfirm(routes.HomeController.welcome())

Cannot locate button web element with xpath using selenium

In the website I want to automate the there is a button I want to click on, if you inspect the element of the button it looks like this:
<input type="submit" value="Login" class="submit">
So I click on this line any then do "Copy xpath" and copy it to my code like this:
val loginButton: WebElement = driver.findElement(By.xpath("""//*[#id="loginForm"]/fieldset/font/font/input """))
loginButton.click()
Its very weird cause in other places it worked perfectly and sometimes I have problems with it, and then I try by cssSelector but here nothing works :/
The path includes two layers of font elements which seems rather fragile to me - any slight changes to the page structure will mean this path fails to match.
I would try a path that considers just the "semantics" of which element you want to target, and not the precise structure of the page. You want the submit button in the login form, so how about a path like
//*[#id="loginForm"]//input[#type="submit"]
which finds any <input type="submit"> anywhere in the form. If there are several submit buttons you can be more specific with #type="submit" and #value="Login"
XPath is prone to break and IMHO overly complicated... I would use a CSS Selector.
driver.findElement(By.cssSelector("input.submit")).click();
This is Java, BTW, but hopefully you can translate it, if needed.

Polymer: manually submitting a form

In polymer I'm trying to manually submit a form. My form looks like this:
<form id="myForm" on-submit="{{ submitForm }}">
<input class="text" value="{{ someValue}}">
<button type="submit">Submit</button>
</form>
And in the polymer object I have:
submitForm: function(e) {
e.preventDefault();
}
Whenever I try to do the following:
document.getElementById('myForm').submit();
the form totally ignores the on-submit attribute and posts the form to a new page.
I'm building a on-screen keyboard for anyone wondering why I would want to do this. I need to submit the form whenever someone hits the enter key on the on-screen keyboard.
Does anyone know why this happens?
A JSBin example to show you the exact problem (see the alerts): http://jsbin.com/wadihija/2/
From the MDN page about submit:
The form's onsubmit event handler will not be triggered when invoking this
method ... it is not guaranteed to be invoked by HTML user agents.
However, calling click on a submit type button seems to work. See here:
http://jsbin.com/tuxac/2/edit
Here is a modification of your jsbin that I believe does what you want:
http://jsbin.com/wadihija/6/edit
Is this along the lines of what you're trying to do? This is a result of a key feature of Shadow DOM: Encapsulation. The elements in your polymer-element's template are not in the main document, and as such, are not available via document.getElementById() and the like.
You could instead call this.shadowRoot.getElementById() and it would work because this inside of your polymer-element's prototype is linked to the host element. Or even better, take advantage of the amazing features Polymer gives you for free. Polymer exposes this.$ to polymer-elements, which contains a key for every element in your template that has an ID! No method call needed, just use this.$.myForm.submit(). Here's the final jsbin.

rails 3 - Add a Button that won't submit a form

I am trying to add a few "next" and "back" buttons to a form. The Idea is to divide the filling-out process into several steps and with these buttons, the div of the current step gets hidden and the next resp. previous step is displayed.
My Problem is that when I add buttons in the following way...
<button class="proceed_button" id="loan_information">Proceed</button>
<button class="cancel_button" id="loan_information">Cancel</button>
... they submit the form.
Is every button inside a form-tag considered to be a submit-button?
If so, how can I change this behavior?
If not, why are they doing it then?
Ok, the solution is that the button needs a type.
<button type="button" class="proceed_button" id="loan_information">Proceed</button>
<button type="button" class="cancel_button" id="loan_information">Cancel</button>
Like this, it won't submit the form anymore.
According to http://w3schools.com/html5/att_button_type.asp the default type is depending on the browser, so you should always specify the type.
I'm not sure that you want a button, maybe you want it to look like a button. Either way, refer to this post: rails 3: display link as button?
Once you have your button, you'll need to update your javascript to prevent anything from happening when it's clicked (assuming you have jquery). It's still nice to provide a real fallback for those dinosaurs without js, so assuming your proceed button submits for users without js, for those with js you'd do something like:
$('#proceed_button').click(function(e) { e.preventDefault(); // Show and hide your divs here });
Also note that in your posted code you should not have two buttons with the same id, your ids and classes look swapped.

One form two action

Hi i have a few form fields i want the on click of button a the control to be sent to action 1 but
on click of button 2 it has to be sent to action 2. Currently i am using js to change the form action dynamically on click. but is there any other solution. I cant do the checking after submit in a same method thet have to be two different methods.
The 2 buttons in this case are view(html data needs to be displayed) and download(same data as csv file). I am using cakephp 1.2 but i feel this is more of a generic problem
One form can only have one action. This is a limitation of HTML. To work around it on the client-side, you need Javascript.
It sounds like the better idea would be to give each submit button a distinctive name and value. This will be submitted like other form elements, so you can detect in the Controller which button was clicked. From there it should only be a matter of switching some View logic in the controller between normal output and download.
I found out there are few solutions
Regular JavaScript to change th form action on click of the buttons
AJAX to send the data to two separate actions on click of separate buttons
As suggested by deceze to do the processing on server side(which was not easily possible in my case)
HTML5 has a formaction attribute for this
<form action="/url" id="myForm">
<input type="submit" value="save1" formAction="/url1" />
<input type="submit" value="save2" formAction="/url2" />
</form>
Here is a fallback if you need it.
if (!('formAction' in document.createElement('input'))){
$('form').on('click', 'input[type=submit]', function (e) {
var attr = this.getAttribute('formAction');
if (attr) {
this.action = attr; //Set the form's action to formAction
}
});
}