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.
Related
I actually created a new inputtype to use TinyMCE, but I saw problem, to make thing simple, I tested with existing "textarea" input type, and found I cannot make it work neither.
so I could have html like below
<div class='editable'>
<p>this is a <b>test</b></p>
</div>
when I make it editable as textarea and then click to edit, I expect to see code like below in the textarea
<p>this is a <b>test</b></p>
instead I see string with all tag stripped, I was told to use loadurl to get the content from backend when it is editted, I did that, which works fine.
But now I have another problem, if I click to edit and then click cancel, the stripped text shows, not the string with tags, any idea what is that? what happens to jeditable reset? where it stores the original text when user click edit and then restore it after user click cancel?
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.
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.
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
I think the title explain my quesion. I need to add a link (or a button) in a label/span (never understand the real difference) by using Struts2 tags.
<s:label cssClass="menu_span">
<s:submit value="Login" />
</s:label>
This doesnt work. Also, i didnt see the s:span (like s:html, s:body, s:head, s:title, s:img, and so on...)
I tried to watch the tag references, but seems that isnt possible do it!
Thanks
First, you don't need to use Struts2 tags where standard HTML tags work fine (which is why there isn't an s:html tag, etc.) Tag libraries in JSP are there to simplify and standardize your HTML output to make it easier on you. When the tag syntax is practically the same as the output generated, they cease to be useful.
Second, what are you trying to achieve by wrapping a submit button in a label? Labels are used to associate text with a form element such as a radio button, checkbox, text field, etc. Buttons are already clickable, so I don't follow what you are trying to do.