I need to Generate PDF report in Java. Earlier when i use Cold Fusion it was easier to export html to PDF, is there any way to convert the html to pdf in JAVA.
I tried JSPDF javascript method to convert this page but that doesn't works.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>View JTC</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<%
if (session.getAttribute("empid") == null) {
response.sendRedirect("index.jsp?message=Session Expired!!");
}
session.setAttribute("cpage", "production");
%>
<jsp:include page="navigationMenu.jsp" />
</head>
<body>
<section class="container-fluid">
<table class="table table-bordered">
<tr>
<th style="width:30%;vertical-align:middle;text-align:center;">logo</th>
<th colspan="2" style="text-align:center;width:70%">Denholm Yam Contracting Comapany L.L.C</th>
</tr>
<tr>
<th rowspan="2" style="text-align:center;vertical-align:middle;">Job Travel Card</th>
<th style="width:10%;">JTC No:</th>
<th></th>
</tr>
<tr>
<th>Date</th>
<th></th>
</tr>
</table>
<table class="table table-bordered">
<tr >
<td style="width:10%;text-align:left;">Project Number</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:10%;text-align:left;">Unit No. / Tag No.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
<tr>
<td>Area Number</td>
<td colspan="2"></td>
<td>Material Class</td>
<td colspan="4"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Drawing No: / ISO Number</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:15%;text-align:left;">JC No:</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Sheet No</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Rev. No.</td>
<td style="width:15%;text-align:left;"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Item Description</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:15%;text-align:left;">ITP Stage Nos.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
</table>
<!-- Fitup data -->
<table class="table table-bordered">
<tr>
<th rowspan="12" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Fabrication Assembly Fit-Up
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Weld/joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Item/Position No.</th>
<th colspan="2">Material Spec Grade</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Size</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Thickness</th>
<th colspan="2">Heat/Plate/TestNo</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Welder No. for tracking</th>
<th colspan="2">Fitup Result</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2" >Sign</th>
</tr>
<tr>
<th>Material 1</th>
<th>Material 2</th>
<th>Material 1</th>
<th>Material 2</th>
<th>Accept</th>
<th>Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
<!-- welding data -->
<table class="table table-bordered">
<tr>
<th rowspan="13" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Welding Details
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">WPS No.</th>
<th colspan="3" class="text-center">Welding Process</th>
<th colspan="3" class="text-center">Welder/Operation No.</th>
<th colspan="2" rowspan="2" class="text-center" >Visual Inspection</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3" >Sign</th>
</tr>
<tr>
<th colspan="3" class="text-center">Passes</th>
<th colspan="3" class="text-center">Passes</th>
</tr>
<tr>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Accept</th>
<th class="text-center">Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="14">Name & Signature of QC Personel</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
</section>
</div>
<script src="assets/jquery/customjs.js" type="text/javascript"></script>
<script src="assets/jquery/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="assets/jquery/popper.min.js" type="text/javascript"></script>
<script src="assets/jquery/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
I need to export this page in landscape and all this content scaled into one page. Is there any way? Thank you in advance.
You can use Flyingsaucer.
Flying Saucer is a pure-Java library for rendering arbitrary
well-formed XML (or XHTML) using CSS 2.1 for layout and formatting,
output to Swing panels, PDF, and images.
Related
I have the next HTML Datatable
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th colspan="3">Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>
</div>
And when I see the table, I get this error: Cannot read property 'fnSetData' of undefined
But when I change the HTML and put this:
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th>Fecha</th><th>Fecha</th><th>Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>
</div>
It works "fine"(I only want a Fecha header instead of 3):
Anyone knows why occur this?
Thanks for your time!
Try like this :
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th colspan="3">Fecha</th>
<th style="display:none;">Fecha</th>
<th style="display:none;">Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>
I am trying to validate search results with searched values. There's a table which displays all the existing keywords. When particular keyword is need to be listed user can search the keyword. search results are displayed in the same table which all keywords were listed before searching.
In particularly when I search for keyword android, "android headlines" and "android" keywords are displayed in the table body. I got the location of these two elements using xpath and printed in the console.But in the console it displays as "Description" and "Oppo" which displays in 1st and 2nd row which had all the keywords listed.
below is the HTML code.
<div id="keyword-grid" class="grid-view">
<table class="items table table-striped">
<thead>
<tr>
<th id="keyword-grid_c0"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=name">Name<span class="caret"></span></a></th>
<th id="keyword-grid_c1"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=behaviour">Behaviour<span class="caret"></span></a></th>
<th id="keyword-grid_c2"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=status">Status<span class="caret"></span></a></th>
<th id="keyword-grid_c3"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=createdAt">Created At<span class="caret"></span></a></th>
<th id="keyword-grid_c4"><a class="sort-link" href="/index.php/keyword/Admin?Keyword_sort=createdBy">Created By<span class="caret"></span></a></th>
<th class="button-column" id="keyword-grid_c5"> </th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Description</td>
<td>Manual</td>
<td><span class="badge badge-success">Active</span></td>
<td>2018-01-16 05:48:02</td>
<td>Admin</td>
<td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/163"><i class="icon-eye-open"></i></a> </td>
<tr class="odd">
<td>Oppo</td>
<td>Manual</td>
<td><span class="badge badge-success">Active</span></td>
<td>2017-11-16 06:32:19</td>
<td>Digitalbox Testing</td>
<td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/161"><i class="icon-eye-open"></i></a> </td>
</tr>
<tr class="even">
<td>android headlines</td>
<td>Manual</td>
<td><span class="badge badge-success">Active</span></td>
<td>2017-11-15 07:53:02</td>
<td>Admin</td>
<td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/160"><i class="icon-eye-open"></i></a> </td>
</tr>
<tr class="odd">
<td>api</td>
<td>Manual</td>
<td><span class="badge badge-success">Active</span></td>
<td>2017-11-15 07:53:02</td>
<td>Admin</td>
<td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/159"><i class="icon-eye-open"></i></a> </td>
</tr>
<tr class="even">
<td>android</td>
<td>Manual</td>
<td><span class="badge badge-important">Deleted</span></td>
<td>2017-11-09 09:43:50</td>
<td>Admin</td>
<td class="button-column"><a class="view" title="View" rel="tooltip" href="/index.php/keyword/View/158"><i class="icon-eye-open"></i></a> </td>
</tr>
</tbody>
</table>
</div>
This is the code I tried to get searched results.
driver1.findElement(By.xpath("//*[#id=\"keyword-grid\"]/table/tbody/tr[1]"));
driver1.findElement(By.xpath("//*[#id=\"keyword-grid\"]/table/tbody/tr[2]"));
System.out.print(driver1.findElement(By.xpath("//*[#id=\"keyword-grid\"]/table/tbody/tr[1]")).getText());
System.out.print(driver1.findElement(By.xpath( "//*[#id=\"keyword-grid\"]/table/tbody/tr[2]")).getText());
How can I print the results of android search?
I am coding in Java using Selenium Webdriver. I am unable to find the LINK Text "License Manager" in the page. When I tried switching to frame called "text". Selenium was unable to locate the frame named "text" please help.
This is my code:
d.switchTo().frame("enterpriseStatus");
d.findElement(By.id("bannerSettingsButton")).click();//settings button
d.manage().timeouts().pageLoadTimeout(15000, TimeUnit.SECONDS);
d.switchTo().window("name=text");//This is where something goes wrong
d.findElement(By.linkText("License Manager")).click();
This is the frame source:
<body>
<div class="tablecontentarea-div" style="width: 90%;">
<table class="tabletitlebar">
<tr>
<td>
<span class="titlepage">Settings</span>
</td>
</tr>
</table>
<div class="tablecontentpanel" style="padding-top: 15px;">
<table style="width:100%" summary="">
<tr>
<td style="width:50%; padding-right:7px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/servers_32x32.png"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Device Management</div>
<div>
Add, manage, configure and delete devices.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Getting Started</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">All Devices</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Manage Agent Assignments</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Policies</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Device Groups</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">NetApp Operations Manager</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Virtualization (Assign ESX Hosts)</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Arrays</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Databases</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/alerting_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Rules & Alerting</div>
<div>
Setup rules that can perform a variety of actions, including running scripts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">All Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Threshold Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Windows Event Log Rules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Asset Change Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Scheduled Rules</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Real Time</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Scripts</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/file_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Files</div>
<div>
Configure file analysis, file rules, assign shares to agents.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">File Analysis Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Directory Analysis Rules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">File Type Groups</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Assign Remote Shares</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Assign Local Shares</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: File Analysis</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Discover VM Targets</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">File Repository</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/user_accounts_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Users</div>
<div>
Add, edit, and remove user accounts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Manage Users</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: User Authentication</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td style="width:50%; padding-left:8px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/server_profiler_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Storage Manager Server</div>
<div>
Configure and view information about your server.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: All</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">About</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: E-mail</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Data Retention</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/web_update_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Updates & Upgrades</div>
<div>
Upload new modules and upgrade your agents and pollers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Upload Modules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Upgrade Agents</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/reports_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">GUI & Reporter</div>
<div>
Configure GUI and Reporting behavior.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Reporter</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: GUI</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/license_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">License Summary</div>
<div>
View your license type and number of storage modifiers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">License Manager</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/Icon.Thwack.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">thwack Community</div>
<div>
Import shared application templates posted on thwack, a community site for Solarwinds users. thwack features helpful devices, tips and downloads from over 20,000 network engineers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Storage thwack Forum</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</body>
To switch to window you have to use WindowsHandle.
You may try using below function provided that you are handeling windows with different titles.
private String mainWindowsHandle; // Stores current window handle
public static boolean swithToWindow(WebDriver driver,String title){
mainWindowsHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles(); // Gets all the available windows
for(String handle : handles)
{
driver.switchTo().window(handle); // switching back to each window in loop
if(driver.getTitle().equals(title)) // Compare title and if title matches stop loop and return true
return true; // We switched to window, so stop the loop and come out of funcation with positive response
}
driver.switchTo().window(mainWindowsHandle); // Switch back to original window handle
return false; // Return false as failed to find window with given title.
}
<%--
Document : resultsQueryFile
Created on : Dec 12, 2014, 11:05:50 PM
Author : Serg Bash
--%>
<%#page language="java" import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Results of search</title>
</head>
<body>
<table border='1'cellspacing='0' cellpadding='0'>
<tr>
<!-- Not used table headers you will can mark as "hidden=''"-->
<th width="10%">
Title:
</th>
<th width="10%">
Thumbnail:
</th>
<th width="10%">
URL:
</th>
<th width="10%">
Type:
</th>
<th width="10%">
Description:
</th>
<th width="10%">
Keywords:
</th>
<th width="10%">
Size:
</th>
<th width="10%">
Custom ID:
</th>
<th width="10%">
Hash:
</th>
<th width="10%">
Status:
</th>
</tr>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); ) {
%>
<!-- Not used table data you will can mark as "hidden=''"-->
<tr>
<td width="10%">
<strong><%=itr.next()%></strong>
</td>
<td width="10%">
<% if(itr.next().toString().contains("null")) out.println("File loading...");
else out.println(itr.next()); %>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<td width="10%">
<%=itr.next()%>
</td>
<tr>
<%}%>
</table>
</body>
</html>
I want print table with some data in one jsp without use others libs, but this print is not correctly works(data mixed in table), because execute one:if or else. Try solve by fynction,but it is no working good.
If your condition meets, then this should work:
<%if(itr.next() == null){ %>
File loading...
<%}else{ %>
<%=itr.next() %>
<%} %>
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].