how to click on a javascript button with htmlunit? - java

Hi I have the following function:
<script type="text/javascript" src="clientscript/vbulletin_md5.js?v=387"></script>
<form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
<input type="hidden" name="s" value="" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_password" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
<table cellpadding="0" cellspacing="3" border="0">
<tr>
Unfortunately the function has no id or name etc. How is it possible to click on the Javascript button and get back the result? Thanks for all your answers in advance.

Use as below
onsubmit="return md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)"
And define md5hash into Javascript with ture/false value

Related

Thymeleaf if else [duplicate]

This question already has answers here:
How to do if-else in Thymeleaf?
(14 answers)
Closed 1 year ago.
I don't know how to wrote this kind of insruction using Thyeleaf.
I've got my view made with html.
<#if updateClient??>
<h2>Modifica del prodotto - ${updateClient.nome}</h2>
<div style="margin: 20px;">
<form method="POST" action="update" id="updateClient">
<input type="hidden" name="id" value="${updateClient.id}"/>
<div>
<label for="name">Name</label>
<input type="text" name="nome" id="nome" value="${updateClient.nome}" />
</div>
<div>
<input type="submit" name="invia" value="Update" />
</div>
</form>
</div>
<#else>
<h2>New Client</h2>
<div style="margin: 20px;">
<form method="POST" action="add" id="newDataClient">
<div>
<label for="nome">Nome</label>
<input type="text" name="nome" id="nome" value="" />
</div>
<div>
<input type="submit" name="invia" value="Add" />
</div>
</form>
</div>
</#if>
This was written using FreeMarker, but I need to use Thymeleaf.
I know simple Thymeleaf instructions, but I don't know how to do this. I read Thymeleaf instructions, and I find how to iterate a list of variables, but not how to create this structure using if and else. And if it's possible create something like this.
<div th:if="${updateClient.nome}">
<div>Edit Form</div>
</div>
<!-- ELSE -->
<div th:unless="${updateClient.nome}">
<div>New Form</div>
</div>

how to place two submit of two different forms side by side on the same line

Guys I'm trying to put two buttons from two different forms on the same line.
I tried to put an id on both buttons so that I can manage them in css.
In particular, what I want to do is put the "delete" button next to the "update" button.
This is what I tried to do but it doesn't work because the "delete" button stays under the "update" button.
//First form
<form action="../updatecustdet" method="post">
<pre>
<c:forEach var="customer" items="${listCustomer}">
<input type="hidden" name="id" value="${customer.id}" />
.
.
.
.
<input type="submit" id="up" value="Update" />
</c:forEach>
</pre>
</form>
//Second form
<form action="../deletefromdetailslist" method="POST">
<input id="cust" name="customer" type="hidden" value="${customer.id}"/>
<input type="submit" id="de" value="Delete"/>
</c:forEach>
</form>
#up {
padding:5px 15px;
background:#ccc;
border:0 none;
cursor:pointer;
-webkit-border-radius: 5px;
border-radius: 5px;
display:inline-block;
}
#de {
padding:5px 15px;
background:#ccc;
border:0 none;
cursor:pointer;
-webkit-border-radius: 5px;
border-radius: 5px;
top:-43px;
}
Heartfelt thanks to those who will help me
Remove the buttons from the form elements and place both of them below the second form. Also give both forms a unique id so that your HTML now matches this:
<form id="update" action="../updatecustdet" method="post">
<pre>
<c:forEach var="customer" items="${listCustomer}">
<input type="hidden" name="id" value="${customer.id}" />
.
.
.
.
</c:forEach>
</pre>
</form>
<form id="delete" action="../deletefromdetailslist" method="POST">
<input id="cust" name="customer" type="hidden" value="${customer.id}"/>
</c:forEach>
</form>
<input type="submit" id="up" value="Update" />
<input type="submit" id="de" value="Delete"/>
Place the following javascript at the bottom of your <body>, otherwise the buttons won't work:
<script>
document.getElementById('up').addEventListener('click', () => document.getElementById('update').submit());
document.getElementById('de').addEventListener('click', () => document.getElementById('delete').submit());
</script>
Use the following javascript if your browser doesn't support ECMA6:
<script>
document.getElementById('up').addEventListener('click', function() {
document.getElementById('update').submit();
});
document.getElementById('de').addEventListener('click', function() {
document.getElementById('delete').submit();
});
</script>
Your CSS is fine, no changed needed.
I may be talking bollocks, but I'm pretty sure form.submit() is part of the HTTP standardized API and as such it's supposed to trigger a single GET/POST/WHATEVER http protocol step.
https://www.rfc-editor.org/rfc/rfc2068#section-9.5
<form id="update" action="../updatecustdet" method="post">
<pre>
<c:forEach var="customer" items="${listCustomer}">
<input type="hidden" name="id" value="${customer.id}" />
.
.
.
.
</c:forEach>
</pre>
</form>
<form id="delete" action="../deletefromdetailslist" method="POST">
<c:forEach var="customer" items="${listCustomer}">
<input id="cust" name="customer" type="hidden" value="${customer.id}"/>
</c:forEach>
</form>
<input type="submit" id="up" value="Update" />
<input type="submit" id="de" value="Delete"/>
<script>
document.getElementById('up').addEventListener('click', function() {
document.getElementById('update').submit();
});
document.getElementById('de').addEventListener('click', function() {
document.getElementById('delete').submit();
});
</script>
</body>
</html>

Change button text on submit with velocity engine / java

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>

Elements change after logging into account in Selenium

I am facing difficulty finding elements using Xpath in selenium. I have a payment page and a field to enter the credit card number. When I simply write a script to enter the credit card number using id it is working. The problem comes when I log into a wallet before entering my CC details. After logging into the wallet, there are two id's by the same name. The script works when I use absolute xpath but that changes when I give the script to someone else.
Html before before into wallet
<form autocomplete="off" name="creditcard-form" method="post" action="submitTransaction?MID=oIVSOk48659529909784&ORDER_ID=PARCEL675442&route=" id="card" class="cc-form validated">
<input type="hidden" name="txnMode" value="CC" />
<input type="hidden" name="txn_Mode" value="CC" />
<input type="hidden" name="channelId" value="WEB" />
<input type="hidden" name="AUTH_MODE" value="3D" />
<input type="hidden" name="CARD_TYPE" id="cardType" value="" />
<input type="hidden" name="walletAmount" id="walletAmountCC" value="0" />
<ul class="grid">
<li class="mb20 card-wrapper">
<label class="mb10" for="cardNumber">ENTER CREDIT CARD NUMBER</label>
<p class="cd">
<input autocomplete="off" type="text" name="" class="ccCardNumber text-input large-input c cardInput type-tel" id="cn" size="16" maxlength="19" style="width: 278px" data-type="cc" value="">
<input type="hidden" name="cardNumber" value="" class="required">
</p>
After logging into Wallet:
<input type="hidden" name="txnMode" value="CC" />
<input type="hidden" name="txn_Mode" value="CC" />
<input type="hidden" name="channelId" value="WEB" />
<input type="hidden" name="AUTH_MODE" value="3D" />
<input type="hidden" name="CARD_TYPE" id="cardType" value="" />
<input type="hidden" name="walletAmount" id="walletAmountCC" value="0" />
<input type="hidden" name="addMoney" value="1" />
<ul class="grid">
<li class="mb20 card-wrapper">
<label class="mb10" for="cardNumber">ENTER CREDIT CARD NUMBER</label>
<p class="cd">
<input autocomplete="off" type="text" name="" class="ccCardNumber text-input large-input c cardInput type-tel" id="cn" size="16" maxlength="19" style="width: 278px" data-type="cc" value="">
<input type="hidden" name="cardNumber" value="" class="required">
</p>
Please help as I am new to programming and can't figure out how to handle this

getText() in WebDriver using Java

The following is the HTML code:
<div id="TITLE" class="text">
<label for="widget_polarisCommunityInput_113_title">Title</label>
<input type="text" name="field(TITLE)" id="widget_polarisCommunityInput_113_title">
<div class="error">This field must not be empty</div>
</div>
I tried to get the text "This field must not be empty" as follows by using WebDriver with Java:
driver.findElement(By.xpath("//div[#id='TITLE']/div")).getText();
driver.findElement(By.xpath("//div[#class='error']")).getText();
But, no text was retrieved. How can I do it? What's the wrong with my code?
Yes, there is a form. HTMl code including form as belows:
<form action="http://community.sandbox.no/content/save.do;jsessionid=F2BF733599D8D9F812B89ACBC20D37C5" method="post">
<div id="widget_polarisCommunityInput_113_leftcolumn">
<input type="hidden" value="article" name="articleType">
<input type="hidden" value="published" name="state">
<input type="hidden" value=" " name="successUrl">
<input type="hidden" value="" name="articleId">
<input type="hidden" value="http://sandbox.no/community/article/" name="redirect_url">
<input type="hidden" value="113" name="widget_id">
<div id="TITLE" class="text">
<label for="widget_polarisCommunityInput_113_title">Title</label>
<input type="text" name="field(TITLE)" id="widget_polarisCommunityInput_113_title">
<div class="error">This field must not be empty</div>
</div>
</form>
You can try as:
driver.findElement(By.xpath("//form/div[#id='widget_polarisCommunityInput_113_leftcolumn']/div[#id='TITLE']/div")).getText();

Categories