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>
Related
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
I'm trying to write a simple auto-login program in Java.
The login page is "login.php" (not mine!), and it has the following form:
<form action="login.php" method="post" name="FormLogin" onsubmit="return validalogin();">
<div class="mainContentTitolo1">Inserisci i dati</div>
<div class="table">
<div class="tr">
<div class="th">
<label for="username">Nome Utente.</label>
</div>
<div class="td">
<input type="text" name="username" id="username" accesskey="m" tabindex="1" size="20" maxlength="16" value=""/>
</div>
</div>
<div class="tr">
<div class="th">
<label for="password">Password</label>
</div>
<div class="td">
<input type="password" name="password" id="password" accesskey="p" tabindex="2" size="20" maxlength="16" value=""/>
</div>
</div>
<input type="hidden" name="refer" value="$refer" />
<input type="hidden" name="invio" value="1" />
<div class="tr">
<div class="tdcolspanallcenter">
<input type="image" src="../../images/conferma.gif" tabindex="3" alt="Conferma login" onclick="return validalogin();" />
</div>
</div>
<div class="tr">
<div class="tdcolspanallcenter">Collegati
</div>
</div>
</div>
</form>
Unfortunately I can't fill "username" and "password" fields.
I tryed to use a link (with CookieHandler and HttpURLConnection classes) like:
https://.../login.php?username=BROWN&password=FOX
But only "username" field results filled and I recive wrong Cookies.
In browser "source code" I can see as result:
[...]
<input type="text" name="username" id="username" accesskey="m" tabindex="1" size="20" maxlength="16" value="BROWN"/>
[...]
<input type="password" name="password" id="password" accesskey="p" tabindex="2" size="20" maxlength="16" value=""/>
[...]
Where is the problem?
Browsers won't let you pass password field(type) values using cookies or from URL, if they would it would be heaven for bots:).
If you insist on auto filling the password field using a parameter from the URL, then change it to <input type="text" name="password" id="password" accesskey="p" tabindex="2" size="20" maxlength="16" value=""/> since anyway every one can see the password in the URL
<form action="Operation">
First number::<input type="text" name="firstno"></input></br>
Second number::<input type="text" name="Secondno"></input></br>
<select name="operation">
<option>Add</option>
<option>Substract</option>
<option>Multiply</option>
<option>Divide</option>
</select> </br>
<input type="submit" value="submit">
</form>
Here instead of a drop down menu I want to use a radio button. How can I implement this? Also I want to perform an operation in servlet page.
for radio buttons try this way
<form action="Operation">
First number::<input type="text" name="firstno"></input></br>
Second number::<input type="text" name="Secondno"></input></br>
<input type="radio" name="operation" value="add">add<br>
<input type="radio" name="operation" value="subtract">Substract<br>
<input type="radio" name="operation" value="Multiply">Multiply<br>
<input type="radio" name="operation" value="Divide">Divide<br>
<input type="submit" value="submit">
</form>
on the servlet try
String radio=request.getParameter("operation");
change your input type="radio"
I'm trying to connect to a URL with a form that has this values:
http://aulavirtual.uv.es/
How can I do this if every time I log value changes (time, token_id, hash) ? Please, help me !! I try with HttpUrlConnection and now with HttpClient 4.
<form name="login" method="post" action="/register/">
<input type="hidden" name="form:mode" value="edit">
<input type="hidden" name="form:id" value="login">
<input type="hidden" name="__confirmed_p" value="0">
<input type="hidden" name="__refreshing_p" value="0">
<input type="hidden" name="return_url" value="/dotlrn/index">
<input type="hidden" name="time" value="1352222384">
<input type="hidden" name="token_id" value="423">
<input type="hidden" name="hash" value="3F8865DB5E6603C296428A5A7C0D66C0256D5626">
<tr>
<td class="formulari">Nom d'usuari</td>
<td class="formulari">
<input type="text" id="username" name="username" value="" size="25" alt="Nom d'usuari"></td>
</tr>
<tr>
<TD class="formulari">Contrasenya</TD>
<TD class="formulari">
<input type="password" id="password" name="password" size="25" ALT="Contrasenya d'accés"></TD>
</tr>
<TR>
<TD COLSPAN="2" class="formulari1">
<div align="center">
<input id="login" type="submit" value=" Entreu " alt="Entrar al Aula Virtual">
<IMG BORDER="0" HEIGHT="25" WIDTH="25" SRC="/resources/key.gif" ALT="Entrar en modo seguro" TITLE="Entrar en modo seguro">
</div>
<!--
<Table COLSPAN="2" class="fonsgifs">
<div align="center" class="titol3">
<strong><U>Altres cursos acadèmics</U></SPAN></strong>
</table>
<BR><BR><BR>
<CENTER>
-->
<!--
<img align="center" src="/images/cabeceraOPEN.png" border = 0 align="center" alt="Conferencia OPEN" />
<BR><img align="center" src="/images/ConferenciaSofwareLibre.png" border = 0 align="center" alt="Conferencia Software Libre" />
<BR>7th OpenACS / .LRN Conference
<BR>Conferencia sobre Software Libre en Educación Superior
</CENTER>
-->
</TD>
</TR>
<TR>
<TD class="formulari1" COLSPAN="2" style="text-align:center">
<BR><BR><BR>
</TD>
</TR>
</FORM>
This form uses hidden parameters for security purposes. Every time http://aulavirtual.uv.es/ is displayed these hidden parameters change.
You could try changing your code to do the following:
GET the http://aulavirtual.uv.es/ page.
Parse the resulting HTML to extract the values of the time, token_id, and hash hidden parameters from the form element.
Do the POST as you do now, but pass in these three values instead of the fixed values you are using now.
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();