Selenium Java Click Radio Button That is in a Table Row - java

So I'm pretty new to Selenium and I'm writing my first program with it. I'm trying to click a radio button that is on a table row. Here is the html code for the row.
<tbody>
<tr id="headerrow">
<td></td>
<td align="center">Name</td>
<td align="left">Account</td>
<td align="center">Status</td>
<td></td>
<td align="center">CW</td>
<td></td>
<td align="center">Last Hit</td>
<td></td>
<td align="right">IP</td>
</tr>
<tr>
<td height="1" bgcolor="#000000" colspan="10"></td>
</tr>
<tr>
<td height="10" colspan="10"></td>
</tr>
<tr id="userrow_1">
<td><input type="radio" name="id" value="1764" onclick="set_it('1');"></td>
<td>John Doe</td>
<td>jdoe</td>
<td align="center" bgcolor="#CCFFCC">Active</td>
<td> </td><td align="center" bgcolor="ccffcc">Yes</td><td> </td><td align="center" nowrap="">Offline - 12/12/12</td><td> </td><td align="right">192.168.1.1</td></tr>
</tbody>
I need to be able to click the button with only the value variable. Thanks for any help.

How about this:
driver.findElement(By.cssSelector("input[name='id'")).click();
This will click the radio button. input[name='id'] is the css selector, that will find your element. And click() method will click on it.

Related

Thymeleaf - Click able URL (Web link) in Table

(I have looked on google, here.. and havent been able to find the answer that could help me).
Goal : Website to be entered as a click able web link
- Link is retrieved from DB as a varchar(100)
Tried all kinds of different solutions.. without any luck - Maybe one of you guys can help me out ? :). thank you in advance.
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>Zip</th>
<th>Website</th>
<th>Email</th>
<th>Phone</th>
<th>Location</th>
<th>Agelimit</th>
</tr>
</thead>
<tbody>
<tr th:each="sps: ${sp}">
<td th:text="${sps.venueId}"/>
<td th:text="${sps.name}"/>
<td th:text="${sps.address}"/>
<td th:text="${sps.city}"/>
<td th:text="${sps.zip}"/>
<td th:text="${sps.website}"/>
<td th:text="${sps.email}"/>
<td th:text="${sps.phone}"/>
<td th:text="${sps.location}"/>
<td th:text="${sps.ageLimit}"/>
</tr>
</tbody>
</table>
You can use any type of tag with Thymeleaf. Is this what you want?
<td>
<a th:href="${sps.website}" th:text="${sps.website}" target="_blank" />
</td>

How to select a link of a Record in the table contains multiple Rows of different class with same class name for each column

<table class="table hover" id="resultTable">
<thead>
<tr>
<th rowspan="1" class="checkbox-col"><input type="checkbox" id="ohrmList_chkSelectAll" name="chkSelectAll" value=""></th>
<th rowspan="1" style="width:400" class="header">Report Name</th>
<th rowspan="1" style="width:95"><span class="headerCell"></span></th>
<th rowspan="1" style="width:95"><span class="headerCell"></span></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><input type="checkbox" id="ohrmList_chkSelectRecord_5" name="chkSelectRow[]" value="5"></td> <td class="left">PIM Sample Report</td>
<td class="left">Run</td>
<td class="left">Edit</td>
</tr>
<tr class="even">
<td><input type="checkbox" id="ohrmList_chkSelectRecord_6" name="chkSelectRow[]" value="6"></td> <td class="left">Sample Report</td>
<td class="left">Run</td>
<td class="left">Edit</td>
</tr>
</tbody>
</table>
I'm a beginner to selenium, so I need a help to click a link (Run)of a Record from multiple Records in the table contains multiple Rows of different class with same class name for each column. I have attached the code snippet.
I tried this Xpath but is not working:
//table[#class='table hover']/tbody/tr/td[text()='PIM Sample Report'] and ./td[text()='Run']
can someone help me to figure out this?
Try to use below XPath :
//td[.="PIM Sample Report"]/following-sibling::td[.="Run"]/a
This should fetch the link "Run" preceded by td with text "PIM Sample Report"

Java based selenium webdriver - click on element in dynamically changing table content by row text ( click input by text in same row )

Im stucked in java based selenium usage, i like to click on input box (within table )by another cell text value
Here is my HTML code:
<DIV class=>
<P class=></P>
<UL></UL>
<FORM id="" onsubmit="" method=post name="" action="">
<TABLE width="100%">
<TBODY>
<TR>
<TD class=></TD></TR></TBODY></TABLE>
<TABLE>
<TBODY>
<TR>
<TD class=></TD></TR>
<TR>
<TD>
<TABLE class="" width="70%">
<TBODY>
<TR class="">
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="">
<TD><INPUT class="" onclick="" CHECKED type=checkbox><INPUT id= value=true type=hidden name=""> </TD>
<TD></TD>
<TD></TD>
<TD></TD></TR></TBODY></TABLE></TD>
<TR>
<TD><INPUT id="" class= onclick='' value="" type=button name=></TD></TR></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
<TR>
<TD class=""></TD></TR>
<TR>
<TD>
<TABLE class=foo width="100%">
<TBODY>
<TR class=foo-header>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="foo-odd">
<TD><INPUT onclick="" value="0" type="radio" name=""> </TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="foo-even">
<TD rowSpan="3"><INPUT onclick="" value="1" CHECKED type="radio" name=""> </TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD></TD>
<TD rowSpan="3"><INPUT id="" class="" value="" type="" name=""></TD></TR>
<TR class="foo-even">
<TD></TD></TR>
<TR class="foo">
<TD>CCC</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><INPUT class="" onclick="" type=checkbox><INPUT id="" value="false" type="hidden" name=""> </TD></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
<TR>
<TD class=""></TD></TR>
<TR>
<TD>
<TABLE class="foo" width="100%">
<TBODY>
<TR class="foo-header">
<TD></TD>
<TD><BR><INPUT id="" class="" onclick="" value="" type="button" name=""></TD>
<TD colSpan="3"></TD>
<TD></TD></TR>
<TR class="foo-odd">
<TD><INPUT value="0" type="radio" name=""> </TD>
<TD></TD>
<TD></TD>
<TD colSpan="2"></TD>
<TD><SELECT class="" name=""> <OPTION value="0"></OPTION> <OPTION selected value="1"></OPTION></SELECT> </TD></TR>
<TR class="foo-even">
<TD rowSpan="2"><INPUT value="1" type="radio" name=""> </TD>
<TD rowSpan="2"></TD>
<TD rowSpan="2"></TD>
<TD></TD>
<TD></TD>
<TD rowSpan="2"><SELECT class="" name=""> <OPTION value="0"></OPTION> <OPTION selected value="1"></OPTION></SELECT> </TD></TR>
<TR class="foo">
<TD>CCC</TD>
<TD></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
</DIV>
I like to click on the second CCC text row related input,(not by only clicking name or xpath) im tried with followings:
driver.findElement(By.xpath(".//td[contains(text(),'CCC')]/preceding-sibling::td")).click();
Code above working in a *very similar html only contains CCC one time (tested with another HTML code )
WebElement services = driver.findElement(By.xpath(".//*[#id='installationAddressForm']/table[4]/tbody/tr[2]/td/table/tbody/tr[4]/td[1][contains(text(),'CCC')]"));
String contents = services.getText();
System.out.println(contents);
Code above able to find text but when combined with the top code(/preceding-sibling::td) it cannot find the input
Please help.Thanks in advance
The expression td[1][contains(text(),'CCC')] selects the first td and tests whether its text contains CCC.
Replace it with td[contains(text(),'CCC')][1].

How to pass data from selected rows using checkboxes from JSP to the server

I'd like to know if there's any way to send data to the server for the selected rows using the checkboxes I've put on those rows? I mean , how can I send only the data of those selected rows to the server?
Here's the html code I use:
<table>
<thead>
<tr class="tableheader">
<td width="10%"></td>
<td width="30%">Vehicle</td>
<td width="40%">Driver</td>
<td width="10%">Mileage</td>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="item">
<tr>
<td align="center">
<input type="checkbox" name="selectedItems"
value="c:out value="${item.numberPlate}"/>"/>
</td>
<td align="left"><c:out value="${item.numberPlate}"/></td>
<td align="left"><c:out value="${item.driver.fullName}" /></td>
<td align="left"><input type="text" name="mileage" value="" /></td>
</tr>
</c:forEach>
</tbody>
</table>
I really hope you can give some guidance on this.
Thanks in beforehand.
When handling the request use request.getParameterValues("selectedItems"). And I don't think it's needed to add [] to names

Javascript Using iframe?

I'm using the jsp of a popup window using the javascript with iframe to show a table of multiple records.When i disabled the table of multiple records,it doesn't prevent the onclick function (hyperlink).
The sample code is :
<tr>
<td colspan="2" class="fieldBG" align="left" valign="middle" width="100%" style="padding:2x">
<iframe name="targetIFrame" id="targetIFrame" src ="/jsp/targetScheduleIFrame.jsp?companyId=<%=zoniacSession.getUserInfo().getCompanyInfo().getCompanyid()%>&loginEmployeeId=<%=zoniacSession.getUserInfo().getEmployeeId()%>" scrolling="yes" width="100%" height="100%" frameborder="0"></iframe></td>
</tr>
1.The above code is in popup window it links to another page namely targetscheduleIFrame.jsp
2.The targetscheduleIFrame.jsp page contains the below code:
for (int k=0; k<jobTriggers.length; k++)
{
Trigger trigger = jobTriggers[k];
%>
<tr>
<th width="4%" class="fieldBG" align="center" valign="top" style="padding:2px">
<zoniac:rect class="zoniac_Edit" fillcolor="#ffffff" style='cursor:hand' strokecolor="#000080" onselectstart="return false" onClick="javascript:deleteQuartzTrigger('<%=trigger.getGroup()%>','<%=trigger.getName()%>');return false;" onMouseOver="window.status='Click here to go to Page'; return true" title="Delete Schedule">DEL</zoniac:rect>
</th>
<td width="14%" class="fieldBG" align="left" valign="top" style="padding:2px">
<a id="hrefDiv" href="javascript:void(0);" onClick="popupWindow('/jsp/targetViewInformation.jsp','TargetViewInfo','700','500','no','no');" class="smallModuleTextLink"><%=trigger.getGroup() + trigger.getName()%></a>
</td>
<td width="9%" class="fieldBG" align="left" valign="top" style="padding:2px">
All days
</td>
<td width="6%" class="fieldBG" align="left" valign="top" style="padding:2px">
<%=(String)trigger.getJobDataMap().get("TriggerTime")%>
</td>
<td width="20%" class="fieldBG" align="left" valign="top" style="padding:2px">
<%=trigger.getDescription()%>
</td>
<td width="12%" class="fieldBG" align="left" valign="top" style="padding:2px">
Jan-22-2010 10:22 AM
</td>
</tr>
<%
}
}
} else {
%>
<tr>
<td colspan="6" class="fieldBG" width="100%" align="center" valign="top" style="padding:2px">
<b>No Records Found</b>
</td>
</tr>
<%
}
%>
What I really Wants:
1.The jsp contains two radio button using inputs to the iframe ,whether it's onclick works or not.
2.The onclick will work one scenario, it will disable another scenario of depends upon the input of radio buttons.
In the parent page which has the iframe, you may have coded the javascript function popupWindow(...)
I suggest you add a radio button check before you push it to the window like
function popupWindow(........){
if(/*see if the radio is checked*/){
// your code here to open the new window
}
}

Categories