How to add pdf inside a thymeleaf pdf using flying saucer - java

I am using java, thymeleaf and flying saucer to generate pdf. I need to add another pdf (by fetching from Aws S3).
I tried iFrame and Embed but it is not working, I am not getting the second pdf in my generated pdf file!
Please help me in finding some way to add the pdf inside of pdf using thymeleaf;
My code-
<body>
<div class="header">
<div style="float: right; color: #000971">
Logo</div>
</div>
<div style="">
<div style="text-align: center; padding-top: 15px; "><h1 style="color:#000971;"><span th:text="${Name}"></span></h1></div>
<div style="padding-top: 30px; margin-left: 50px">
<h1 style="color:darkcyan;"><u>Report:</u></h1>
<h1 style="color: darkcyan; margin-top: 250px">Report By: <br />
<span style="color:#000971;" th:text="${firstName}"></span> <span style="color:#000971;" th:text="${lastName}"></span></h1>
<!-- <h1 style="color: #006382;">Last Name: <span style="color:#6FB8D9;" th:text="${lastName}"></span></h1>-->
<br/>
<div id="lastContent" style="margin-top: 80px">
<h2 style="color: darkcyan">REPORT DATE:</h2>
<h2 style="color: #000971">Created Date: <span th:text="${createdTime}"></span></h2>
<h2 style="color: #000971">Last Updated Date: <span th:text="${lastUpdated}"></span></h2>
</div>
</div>
</div>
<div>
<iframe src="http://www.wright.edu/~david.wilson/eng3000/samplereport.pdf" style="width:100%;height:700px;"></iframe>
<embed src="./samplereport.pdf" width="600" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" />
</div>
</body>

Related

I reference my CSS page to my HTML and it simply won't have any effect

I am currently working on a java project and have made an html page with a design (css) page to accompany it. I have referenced it but it still won't have any effect. I hard reloaded the page still no changes. Don't really understand why this is happening. I keep getting "net::ERR_ABORTED 404" on localhost. The stylesheet file name is indeed correct (being loginStyle.css). They are also both located in the same folder. Would appreciate any help. Thanks!
.btn-color {
background-color: #0e1c36;
color: #fff;
}
.profile-image-pic {
height: 200px;
width: 200px;
object-fit: cover;
}
.cardbody-color {
background-color: #ebf2fa;
}
<!DOCTYPE html>
<html lang="en" xmlns:thymeleaf.org>
<head>
<link rel="stylesheet" type="text/css" href="loginStyle.css" />
</head>
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<h2 class="text-center text-dark mt-5">Welcome</h2>
<div class="card my-5">
<form class="card-body cardbody-color p-lg-5" th:action="#{/userLogin}" th:object="${user}" method="post">
<div class="text-center">
<img src="https://cdn.pixabay.com/photo/2016/03/31/19/56/avatar-1295397__340.png" class="img-fluid profile-image-pic img-thumbnail rounded-circle my-3" width="200px" alt="profile">
</div>
<div class="mb-3">
<input type="text" class="form-control" id="Username" aria-describedby="emailHelp" placeholder="User Name" th:field="*{Id}">
</div>
<div class="mb-3">
<input type="password" class="form-control" id="password" placeholder="password" th:field="*{password}">
</div>
<div class="text-center"><button type="submit" class="btn btn-color px-5 mb-5 w-100">Login</button></div>
<div id="emailHelp" class="form-text text-center mb-5 text-dark">Not Registered?
<a href="#" class="text-dark fw-bold"> Create an Account
</a>
</div>
</form>
</div>
</div>
</div>
</div>
</html>

How to display the dynamic text availalble between div tags in selenium webdriver using JAVA

I have been trying to automate the password reset functionality. So when the email is available we get a message and when not another message, both are in the same tag but dynamic depending on the email id. How to display this dynamic text?
The source code is
if($.trim(response) == '1'){
$(".resultreset").html("<div class='alert alert-success'>New Password sent to "+resetemail+", Kindly check email</div>");
}else{
$(".resultreset").html("<div class='alert alert-danger'>Email Not Found</div>");
} }); });
The tags are like
<div class="resultreset">
<div class="alert alert-danger">Email Not Found</div>
</div>
and
<div class="resultreset">
<div class="alert alert-success">New Password sent to "xxx#xxx.com", Kindly check email</div>
</div>
How to get the text "Email Not Found" or New Password sent to "xxx#xxx.com", Kindly check email and display using JAVA in selenium webdriver.
I have tried to locate it using the xpath .//*[#id='passresetfrm']/div[1]/div/text(), but the webdriver is not able to locate the element.
Also tried with driver.findElement(By.classname("alert")).gettext();, even this is not recognized.
It locates the class, but not the message.
The complete source code for the forgot password section
<div id="ForgetPassword" class="modal wow fadeIn animated animated in" tabindex="" role="dialog" aria-labelledby="ForgetPassword" aria-hidden="true" style="visibility: visible; animation-name: fadeIn; display: block; padding-right: 17px;">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">
<span class="ink animate" style="height: 21px; width: 21px; top: 2.5px; left: -5.56665px;"></span>
×
</button>
<h4 class="modal-title">
<i class="fa fa-asterisk"></i>
Forget Password
</h4>
</div>
<div class="modal-body">
<form id="passresetfrm" method="POST" action="" accept-charset="UTF-8" onsubmit="return false;">
<div class="resultreset">
<div class="alert alert-danger">Email Not Found</div>
</div>
<div class="input-group">
<input id="resetemail" class="form-control" placeholder="your#email.com" name="email" required="" type="text">
<span class="input-group-btn">
<button class="btn btn-primary resetbtn" type="submit">
<span class="ink animate" style="height: 62px; width: 62px; top: -98.7167px; left: -11.5167px;"></span>
Reset
</button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
Identify the element and use getText to get the embedded text in that tag. Below code might give you some idea.
webElement result = driver.findElement(by.xpath("//div[#class='resultreset']/div"))
String message = result.getText();
Hope this helps. Thanks.
I'm not sure why getText() is not working for you, but can you try getAttribute("textContent") ?
String textToVeify = driver.findElement(By.classname("alert")).getAttribute("textContent");

How to retrive text from a div tag

In my SeleniumWebdriver test, I need to retrieve the text of a fieldlabel-content based on the fieldlabel-label to ensure info provided for every fieldlable-label is correct.
Here is the HTML code:
<div class="gridlayout-row" style="padding-top: 0px;">
<div class="gridlayout-column" style="padding-left: 0px; width: calc((100% - 110px) * 0.166667 + 10px);">
<div class="gridlayout-content">
<label class="fieldlabel">
<div class="fieldlabel-label">Type</div>
<div class="fieldlabel-content">Paid</div>
</label>
</div>
</div>
<div class="gridlayout-column" style="padding-left: 10px; width: calc((100% - 110px) * 0.166667 + 10px);">
<div class="gridlayout-content">
<label class="fieldlabel">
<div class="fieldlabel-label">Expires</div>
<div class="fieldlabel-content">Jul 27, 2017</div>
</label>
</div>
</div>
<div class="gridlayout-column" style="padding-left: 10px; width: calc((100% - 110px) * 0.166667 + 10px);">
<div class="gridlayout-content">
<label class="fieldlabel">
<div class="fieldlabel-label">Last update</div>
<div class="fieldlabel-content">Jul 12, 2017</div>
</label>
</div>
</div>
You can find div element with class fieldlabel-label using its text and use following-sibling to get element with fieldlabel-content class.
driver.findElement(By.xpath("//div[#class='fieldlabel-content and contains(text(), 'Expires')']/following-sibling::div[#class='fieldlabel-content']"));
You can try this Xpath :- //div[text()="Type"]/following-sibling::div[#class="fieldlabel-content"]
In above xpath you can provide dynamic 'fieldlable-label' text in first div. On the biases of that you can get respective fieldlabel-content value.
driver.findElement(By.xpath("//div[text()="Type"]/following-sibling::div[#class="fieldlabel-content"]")).getText();

button posts to current address

I'm having a problem with form. When I use button it's using post method to current address instead of one specified in form. I got no idea what's wrong in that form. I would really appreciate some help.
<form th:action:="#{/shoppingCart/addItem}" method="post">
<input hidden="hidden" th:value="*{book.id}"/><!--both name and value are taken care of by that syntax -->
<div class="row" style="margin-top: 120px">
<div class="col-xs-3">
<a th:href="#{/bookshelf}">Back to book list. </a><br/>
<img class="img-responsive shelf-book" th:src="#{adminPath}+#{/image/book/}+${book.id}+'.png'"/>
</div>
<div class="col-xs-9">
<h3 th:text="${book.title}">Book Title</h3>
<div class="row">
<div class="col-xs-5">
<h5><strong>Author: </strong><span th:text="${book.author}"></span></h5>
<p><strong>Publisher: </strong><span th:text="${book.publisher}"></span></p>
<p><strong>Publication Date: </strong><span th:text="${book.publicationDate}"></span></p>
<p><strong>Language: </strong><span th:text="${book.language}"></span></p>
<p><strong>Category: </strong><span th:text="${book.category}"></span></p>
<p><strong><span th:text="${book.format}"></span></strong> : <span th:text="${book.numberOfPages}"></span> pages</p>
<p><strong>ISBN: </strong><span th:text="${book.isbn}"></span></p>
<p><strong>Shipping weight: </strong><span th:text="${book.shippingWeight}"></span> kg</p>
</div>
<div class="col-xs-5">
<div class="panel panel-default" >
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<h4>Our price: <span>$ <span style="color: #db3208;" th:text="${book.ourPrice}"></span></span> </h4>
<p>List price: <span>$ <span style="text-decoration: line-through" th:text="${book.listPrice}"></span></span> </p>
<p>You save: <span th:text="${#numbers.formatDecimal((book.listPrice - book.ourPrice), 0, 'COMMA', 2, 'POINT')}"></span> </p>
<span>Qty: </span>
<select>
<option th:each="qty : ${qtyList}" th:value="${qty}" th:text="${qty}" ></option>
</select>
</div>
<div class="col-xs-6">
<h4 th:if="*{book.inStockNumber>9}" style="color: green">In Stock;</h4>
<h4 th:if="*{book.inStockNumber>0 and book.inStockNumber<10}" style="color: green">Only <span th:text="${book.inStockNumber}"></span> left.</h4>
<h4 th:if="*{book.inStockNumber==0}" style="color: darkred">SOLD OUT.</h4>
<button type="submit" class="btn btn-warning" style="color: black; border: solid 1px">Add to cart</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr style="color: black; height: 2px; width: 100%"/>
<p th:utext="${book.description}"></p>
</div>
</form>
Sites html code, after using the button
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="" />
<meta name="author" content="" />
<link rel="icon" href="../../favicon.ico" />
<title>Bookstore</title>
<!--Font Awesome-->
<link rel="stylesheet" href="/lib/components-font-awesome/css/font-awesome.min.css" />
<!-- Bootstrap core CSS -->
<link href="/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Custom styles for this template -->
<link href="/css/style.css" rel="stylesheet" />
</head>
<body>
<div>
<div class="page-top" style="width: 100%; height: 20px; background-color: #f46b42; margin-top: -15px"></div>
<!-- Static navbar -->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bookstore</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="/bookshelf">Books <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Browse the bookshelf</li>
<li>Opening hours & directions</li>
<li>FAQ</li>
</ul>
</li>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>SHOPPING CART</li>
<li>MY ACCOUNT</li>
<li></li>
<li></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
</div>
<div class="container">
<hr style="position: absolute; background-color: #333; z-index: -1; height: 6px; width: 100%; margin-top: 100px" />
<div class="row">
<div class="col-xs-8"><h2 class="section-headline"><span>Welcome guest.</span></h2> </div>
<div class="col-xs-4"><img src="/image/logo.png" class="img-responsive" /></div>
</div>
<img src="/image/wood.png" class="img-responsive" style="margin-top: -75px" />
<form th:action:="#{/shoppingCart/addItem}" method="post">
<input hidden="hidden" value="1" /><!--both name and value are taken care of by that syntax -->
<div class="row" style="margin-top: 120px">
<div class="col-xs-3">
Back to book list. <br />
<img class="img-responsive shelf-book" src="http://localhost:8081/adminportal/image/book/1.png" />
</div>
<div class="col-xs-9">
<h3>tre</h3>
<div class="row">
<div class="col-xs-5">
<h5><strong>Author: </strong><span>wss</span></h5>
<p><strong>Publisher: </strong><span>wew</span></p>
<p><strong>Publication Date: </strong><span>5666</span></p>
<p><strong>Language: </strong><span>polish</span></p>
<p><strong>Category: </strong><span>Biography</span></p>
<p><strong><span>Hardcover</span></strong> : <span>66</span> pages</p>
<p><strong>ISBN: </strong><span>667</span></p>
<p><strong>Shipping weight: </strong><span>7.0</span> kg</p>
</div>
<div class="col-xs-5">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<h4>Our price: <span>$ <span style="color: #db3208;">10.0</span></span> </h4>
<p>List price: <span>$ <span style="text-decoration: line-through">12.0</span></span> </p>
<p>You save: <span>2.00</span> </p>
<span>Qty: </span>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div class="col-xs-6">
<h4 style="color: green">Only <span>8</span> left.</h4>
<button type="submit" class="btn btn-warning" style="color: black; border: solid 1px">Add to cart</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr style="color: black; height: 2px; width: 100%" />
<p><p>hhgvhhu</p></p>
</div>
</form>
</div>
<div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/lib/jquery/dist/jquery.min.js"></script>
<script src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
</div>
</body>
</html>
Looks like you've got a typo:
th:action:="#{/shoppingCart/addItem}"
:=

How to select a text from table and click with selenium

In order page when I make a payment, I get the created payment listed in payments list page. The created payment will always list on the first row of the table. I want to know how to get a text “This is Project:
“ and also be able to click on it. Every payment has its own id in a row i.e. Here is the snipped of the table:
<div id="PAYMENT-CONTAINER" style="clear:both">
<div class="list-widget" id="PAYMENT-LIST">
<ul style="visibility: visible;" class="table">
<li id="393118">
<div class="no-expand col0" style="text-align: center; width: 31px;"><input type="checkbox" class="rowSelect" value="393118"></div>
<div class="no-expand col1" style="text-align: center; width: 57px;">
<span class="tag untagged">•••</span>
</div>
<div class="col2" style="text-align: center; width: 155px;">
07/28/2015
</div>
<div class="col3" style="width: 401px;">
5280 FAST PITCH
</div>
<div class="col4" style="width: 344px;">
This is Project:
</div>
<div class="col5" style="text-align: right; width: 213px;">
$25.00
</div>
<div class="col6" style="width: 188px;">
Stacey Smith
</div>
<div class="col7" style="width: 178px;">
In Process
</div>
</li>
<li id="393119">
<div class="no-expand col0" style="text-align: center; width: 31px;"><input type="checkbox" class="rowSelect" value="393119"></div>
<div class="no-expand col1" style="text-align: center; width: 57px;">
<span class="tag untagged">•••</span>
</div>
<div class="col2" style="text-align: center; width: 155px;">
07/28/2015
</div>
<div class="col3" style="width: 401px;">
5280 FAST PITCH
</div>
<div class="col4" style="width: 344px;">
Donations are for good cause
</div>
<div class="col5" style="text-align: right; width: 213px;">
$26.00
</div>
<div class="col6" style="width: 188px;">
Stacey Smith
</div>
<div class="col7" style="width: 178px;">
In Process
</div>
</li>
You can get the text WebElement by using below xpath:
//div[#class='col4']
or
//div[contains(text(),'This is project');
you can use any one of the xpath to find web element.
Something like this:
WebElement element = driver.findElement(By.xpath("//div[#class='col4']"));
//Print text
print(element.getText());
//Click on that element if it is clickable.
element.click();
Xpath selector for your case is: //div[contains(text(), 'This is Project:')]
. For example, if instance of webdriver is called like "driver", then code should be:
driver.findElement(By.xpath("//div[contains(text(), 'This is Project:')]")).click();
If your required text "This is Project:" always appears in first row, then you can try below xpath:-
//li[1]/div[#class='col4']
//to get text:-
driver.findElement(By.xpath("//li[1]/div[#class='col4']")).getText();
//to click on it:-
driver.findElement(By.xpath("//li[1]/div[#class='col4']")).click();

Categories