Submit Button is not getting selected..no error also - java

HTML code:
<button id="welcomeContinue" class="btn btn-primary padlock active-removal" type="submit">
<span class="icon-padlock"></span>
CONTINUE
</button>
<input class="btn btn-primary padlock disabled" type="hidden" value="" title="Continue" name="continueanonymousSubmit" alt="Continue">
<input type="hidden" value=" " name="_D:continueanonymousSubmit">
code:
driver.findElement(By.id("welcomeContinue")).click();
How can i select submit button and proceed to next page

You can try using submit() method on a button instead of clicking.
Also, may be some info should be added for submitting to work: some required fields should be filled. Check this option
There are may be some JS scripts running that prevent submit for working

driver.findElement(By.xpath("//button[#type='submit']")).click()

Related

Getting values in servlet from two different forms

I'm trying to get two values from a jsp page to a servlet, but both are in separate forms:
Drop-down selector:
<form action="${pageContext.request.contextPath}/helloServlet" method="post">
<button class="dropbtn" type="submit" value="test" name="curr_val" id="dropbtn">Choose a Value</button>
</form>
Menu buttons:
<form action="${pageContext.request.contextPath}/helloServlet" method="post">
<button type="submit" name="button" class="demobtn">Menu button 1</button>
<button type="submit" name="button" class="demobtn">Menu button 2</button>
<button type="submit" name="button" class="expbtn">Menu button 3</button>
...
Is it possible to get the value from "Drop-down selector" when I press a "Menu" button? Or do I have to have everything wrapped in one form?
There are a couple of things that might do it for you:
1- If you could put some id's into your forms like form1 with id="form1" and form2 with id="form2", you can do something like:
HTML:
<input type="button" value="Click Me!" onclick="submitForms()" />
JS function:
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
2- If you could put name into your forms, you could do something like this:
submitForms = function(){
document.forms["form1"].submit();
document.forms["form2"].submit();
}
3- If you cannot modify the HTML and are fine with submitting all the forms on the very JSP, you can do something like:
$('form').submit();

Element is not clicking on openBravo Application

I'm working an OpenBravo application. I'm facing a problem with clicking an element when tried with a text id class. I'm able to find the element but the element is not clicking on that button.
I used the click() event with the action sendKeys() in JavaScript but it is still not working.
driver.findElement(By.id("terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton")).click();
Html format is
<div id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control">
<input style="width: 100%;margin-bottom:0px;background-color: #E8E8E8;width:300px" readonly="readonly" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EmployeeName" type="text" value="Kanika Sachdeva">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control2">
<input style="width: 100%;margin-bottom:0px;width:300px" maxlength="15" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EMPLOYEEID" placeholder="Enter Employee Id ..." type="text">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control3">
<button class="enyo-tool-decorator btnlink btnlink-gray modal-dialog-button" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton">OK</button>
</div>

Form gets submitted on ENTER button

I have form as given below. Now, when I enter something in the #search_string and press ENTER button it automatically takes it to the action=Paid... I'm not sure why the form gets submitted on the ENTER button..
<!--<div id="startsearchbox">-->
<form id="bigsearchform_new" method="post" action="Paid">
<!--<label style="display:none" for="search_string">SEARCH</label>-->
<input id="search_string" name="search_string" type="text" class="startnewsearch rounded" placeholder="Search..." maxlength="500" >
<input id="searchButton1" type="button" class="searchButton" title="Click here to search the database">
<input type="hidden" name="antiCSRF" value="{{acsrf}}" />
<input type="hidden" name="session_id" value="{{session_id}}" />
<input type="hidden" name="commodity_id" id="commodity_id" />
</form>
It's default behavior of the browser to submit the form on ENTER button. If you want to prevent form submitssion use onSubmit event handler.
That is the default behavior for an HTML form, see http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#implicit-submission

navigating through tab key not working properly

in my jsp, when i navigate through tab key it skips my Save and Reset button. and move to next component in my page. even though i have not used tabindex in my jsp files. please suggest what could be the reason. thanks
code is like:
<div>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" class="button" name="_eventId_search" value="Search"/>
<span class="save_button_common" onClick="submitForm('save')">Save</span>
<span class="reset_button_common" onClick="submitForm('reset')">Reset</span>
</div>
May be because it is not input type , you can explicitly try setting tabIndex
Try:
<div>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" class="button" name="_eventId_search" value="Search"/>
<input type="button" class="save_button_common" onClick="submitForm('save')">Save</input>
<input type="button" class="reset_button_common" onClick="submitForm('reset')">Reset></input>
</div>
Note if it's a form you need input type="button" rather than just using <button> which you can otherwise just for straight links that don't submit a form. This is particularly relevant with Internet Explorer that treats the button tag somewhat differently to other browsers (submitting the "value=" rather than the enclosed text or something like that)

How can I tell which submit button was clicked

I have several different submit buttons on my JSP in one form tag that all point to the same servlet. I need to know which submit button was clicked. How can I find out which button was clicked?
if request.getParameter("button-name") is not null then this is the button that was pressed
Each Submit button should have a different name:
<input type="submit" value="This is a submit button" name="submit1">
<input type="submit" value="Another submit button" name="submit2">
<input type="submit" value="Yet another submit button!" name="submit3">
Then, the name of the input should appear in the parameters sent to wherever the form is posting to, something like
post.jsp?key=value&submit3=&....
http://www.w3schools.com/tags/tag_input.asp
This is kind of similar to the DispatchAction in Struts. What they do is to have a hidden field, and when you submit the form, have onClick() set the value to specify which action is taken.
<input type="hidden" name="dispatchAction"/>
<input type="submit" value="Edit" onClick="setDispatchAction('edit')">
<input type="submit" value="Delete" onClick="setDispatchAction('delete')">
<button type="submit" name="somename" value="button1">some text</button>
<button type="submit" name="somename" value="button2">some other text</button>
you will have the post variable "somename" set to the according value, no matter the dispalyed value.

Categories