<div id="rightContent" style="display: inline-block; width: 700px; vertical-align: top;">
<div>
<h1><em class="SomethingHeading">Something</em></h1>
</div>
<div class="content scaffold-list" role="main">
<h1>Search</h1>
<form action="/SomethingArchiveUI/search/search" method="post">
<table>
<tbody>
<tr>
<td>ID/Registration Number:</td>
<td>
<**input type="text" name="idNumber" maxlength="20" value="" id="idNumber"**>
</td>
</tr>
<tr>
<td>Client Name:</td>
<td>
<input type="text" name="clientName" maxlength="50" value="" id="clientName">
</td>
</tr>
<tr>
<td>Client Surname:</td>
<td>
<input type="text" name="clientSurname" maxlength="50" value="" id="clientSurname">
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="_dateRange"><input type="checkbox" name="dateRange" value="true" id="dateRange"><label for="dateRange"> Use date range?</label>
</td>
</tr>
<tr>
<td colspan="2"><p>From: <input type="text" name="fromDate" value="" maxlength="10" id="fromDate" class="hasDatepicker"> To: <input type="text" name="toDate" value="" maxlength="10" id="toDate" class="hasDatepicker"></p></td>
</tr>
</tbody>
</table>
<div style="display: inline;">
<div id="divSubmit">
<input type="submit" name="cmdSearch" class="buttons" value="Search" id="cmdSearch">
</div>
<div id="divBusy" style="display: none;">
Busy Searching...
</div>
</div>
</form>
<table id="customerIdentificationList" style="display: block;">
</table>
<div id="loadingMessage" style="display: none;">
Loading. Please wait.
</div>
</div>
</div>
I used this code below for logging into the Application, but similar code doesn't seem to work on this form above. I'm trying to find the 'idNumber' element:
driver.findElement(By.xpath("//*[#id='idnumber']")).sendKeys("Username");
driver.findElement(By.xpath("//*[#id=\'password\']")).sendKeys("Password");
driver.findElement(By.xpath("//*[#id=\'submit\']")).click();
The error i get is: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":
Looking forward to your responses.
Use : .//input[#id='idnumber']
Why not just use By.id()?
driver.findElement(By.id("idNumber"));
I don't know the reason why you can't use By.id() or By.xpath in this case. But you can try to find the input using text in previous td. I hope next code will help:
driver.findElement(By.xpath("//td[text()='ID/Registration Number:']/following-sibling::td/input")).sendKeys("Username");
Try using the below way -
First get the root element and keep it to a WebElement object. Then find for input element idNumber
WebElement elem = driver.findElement(By.cssSelector("#rightContent > div.content.scaffold-list > form"));
elem.findElement(By.id("idNumber")).sendKeys("Username");
So now I got a admin panel for my website I decided to try some small things but I am not getting there yet.
So whenever I disable or enable a user I get a nice good/bad notification saying what happened but ofcourse the button will stay the same. Is their a way to change this according to the function?
#parse("/velocity/layout.vm")
##mainLayout()
<table id="adminPanel">
<tr>
<th>Email</th>
<th>Name</th>
<th>Reset Password</th>
<th>IsActive</th>
<th>Delete</th>
</tr>
#if($resetpassword)
<p class="good notification">$msg.get("RESET_PASSWORD")</p>
#elseif($blockuser)
<p class="bad notification">$msg.get("BLOCK_USER")</p>
#elseif($unblockuser)
<p class="good notification">$msg.get("UNBLOCK_USER")</p>
#elseif($deleteuser)
<p class="bad notification">$msg.get("DELETE_USER")</p>
#end
#foreach($user in $users)
#if($user.getIsadmin())
<div class="col">
<tr>
<th>$user.getEmail()</th>
<th>$user.getFirstname() $user.getSurname()</th>
<th><form method="post">
<input type="hidden" name="post" value="reset">
<input type="hidden" name="email" value="$user.getEmail()">
<input type="submit" value="Reset Password" disabled>
</form></th></th>
<th><form method="post">
<input type="hidden" name="post" value="block">
<input type="hidden" name="email" value="$$user.getEmail()">
<input type="submit" value="IsActive" disabled>
</form></th></th>
<th><form method="post">
<input type="hidden" name="post" value="delete">
<input type="hidden" name="email" value="$user.getEmail()">
<input id="button" type="submit" value="Delete" disabled>
</form></th>
</tr>
</div>
#else
<div class="col">
<tr>
<th>$user.getEmail()</th>
<th>$user.getFirstname() $user.getSurname()</th>
<th><form method="post">
<input type="hidden" name="post" value="reset">
<input type="hidden" name="email" value="$user.getEmail()">
<input type="submit" value="Reset Password">
</form></th></th>
<th><form method="post">
<input type="hidden" name="post" value="block">
<input type="hidden" name="email" value="$user.getEmail()">
<input type="submit" value="Disable">
</form></th></th>
<th><form method="post">
<input type="hidden" name="post" value="delete">
<input type="hidden" name="email" value="$user.getEmail()">
<input type="submit" value="Delete">
</form></th>
</tr>
</div>
#end
#end
</table>
#end
It is very unclear in your question about what buttons you want the text to be changed. Since I see only two buttons in your code, I can recommend you to do something like this (assuming that the User object has enough details to know whether a user is blocked or not).
<input type="button" #if ($user.isBlocked()) value="Unblock" #else value="Block" #end>
I want to jump between textfields, but these fields are generated dynamically through an iterator from struts-tags:
<s:iterator value="aList">
<td width="50px" align="center">
<s:textfield name="solField" size="2" maxlength="1" style="text-transform: uppercase; text-align:center"/>
</td>
</s:iterator>
I tried jumping with javascript but having the same field name is not working properly.
The code in the browser is (with three items in the list to iterate):
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
Any ideas?
Thanks in advance
How about this? (using jQuery)
$(document).on('keyup', 'input', function(){
if($(this).val().length >= $(this).attr('maxlength'))
{
$(this).nextAll('input:first').focus();
// OR even
// $(this).next('input').focus();
}
});
Is that what you're looking for? http://fiddle.jshell.net/C3jeY/
I have below mentioned code in JSP Page. I am able to save all the values from below text boxes to DB. However, I read each text box name in my servlet (request.getParameter()) to save the fields. Is it possible to improve this code? like for example : to save all the values of one particular column in an array and save to db. If yes; please show an example that helps me. Also how to ignore if a row is empty. for example, user fills only two rows and rest rows are empty. I want to save only first two rows in DB.
<table class="cmn-table" id="t1" border="1" style="margin-left: 0.2em; margin- right:0em">
<col width="5%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<tr>
<th>Sl.No</th>
<th>Source IP Address</th>
<th>Destination IP Address</th>
<th>Service and Port (TCP, UDP, etc.)</th>
<th>Start Date</th>
<th>Expiration Date</th>
</tr>
<tr>
<td style="align:center"> 1 </td>
<td><input type="text" name="name" id="name" size="20"> </td>
<td><input type="text" name="name1" id="name1" size="20"> </td>
<td><input type="text" name="name2" id="name2" size="20"> </td>
<td><input type="text" name="name3" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td style="align:center"> <label> 2 </label> </td>
<td><input type="text" name="name5" id="name" size="20"> </td>
<td><input type="text" name="name6" id="name" size="20"> </td>
<td><input type="text" name="name7" id="name" size="20"> </td>
<td><input type="text" name="name8" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name9" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label> 3 </label> </td>
<td><input type="text" name="name10" id="name" size="20"> </td>
<td><input type="text" name="name11" id="name" size="20"> </td>
<td><input type="text" name="name12" id="name" size="20"> </td>
<td><input type="text" name="name13" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name14" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>4 </label> </td>
<td><input type="text" name="name15" id="name" size="20"> </td>
<td><input type="text" name="name16" id="name" size="20"> </td>
<td><input type="text" name="name17" id="name" size="20"> </td>
<td><input type="text" name="name18" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name19" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>5 </label> </td>
<td><input type="text" name="name20" id="name" size="20"> </td>
<td><input type="text" name="name21" id="name" size="20"> </td>
<td><input type="text" name="name22" id="name" size="20"> </td>
<td><input type="text" name="name23" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name24" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
</table>
As much as i understand, you want to get rid of calling request.getParameter on all the input fields.
Why dont you use below:
request.getParameterMap()
This gives you a map of all the parameter names and values. So, you can iterate through the map and keys in the map are parameter names and value for that key is/are the values for that parameter. Its a simple iteration over map. While iterating through the map, you can actually prepare your DB query as well based on other checks like null check.
I'm trying to submit (post) a multidimensional (2D) html-form to a JSP.
In HTML there's the following code:
<tr class="odd">
<td>
<input type="checkbox" name="row1['attribute']" value="Druckerei" id="attribute-1" />
</td>
<td>
<label for="attribute-1">Druckerei</label>
</td>
<td>
<input type="text" name="row1['weight']" size="3" value="0" />
</td>
</tr>
<tr class="even">
<td>
<input type="checkbox" name="row2['attribute']" value="Erscheinungstag" checked="checked" id="attribute-2" />
</td>
<td>
<label for="attribute-2">Erscheinungstag</label>
</td>
<td>
<input type="text" name="row2['weight']" size="3" value="0" />
</td>
</tr>
Is there in JSP a way to handle the 2D post data (perhaps similar to PHP)?
Would it be easier if I had different HTML-Code?
Thank you very much!
No you cannot have 2D array like Rows and Columns. But you can achieve this by sending multiple values for a POST data parameter which works like this:
Your Form might look like this:
<tr class="odd">
<td>
<input type="checkbox" name="attribute" value="Druckerei" id="attribute-1" />
</td>
<td>
<label for="attribute-1">Druckerei</label>
</td>
<td>
<input type="text" name="weight" size="3" value="0" />
</td>
</tr>
<tr class="even">
<td>
<input type="checkbox" name="attribute" value="Erscheinungstag"
checked="checked" id="attribute-2" />
</td>
<td>
<label for="attribute-2">Erscheinungstag</label>
</td>
<td>
<input type="text" name="weight" size="3" value="0" />
</td>
</tr>
And your POST Data will be sent like:
url?attribute=Druckerei,Erscheinungstag&weight=3,3
From the servlets you can access the the POST parameter like:
String[] attributes = request.getParameterValues("attribute");
String[] weights = request.getParameterValues("weight");