i need your experience in casperjs!
I am trying to access a web page (which is not an issue) and to navigate through a html tab.
When i access the page it is by default always showing the first tab "General" but i need to switch to "Options" tab so that i can access one field that i am interested to modify the value!
Sorry, can't post images yet!
Html code:
<b> <b>
<table class="commonfont" cellpadding="0" cellspacing="0" background="/tab_between.png" border="0">
<tbody>
<tr>
<td><input name="" src="/tab_sel_left.png" border="0" type="image"></td>
<td align="center" background="/tab_sel_bg.png">
General
</td>
<td><input name="" src="/tab_sel_right.png" border="0" type="image"></td>
<td width="1"></td>
<td><input name="" src="/tab_unsel_left.png" border="0" type="image"></td>
<td align="center" background="/tab_unsel_bg.png">
Options
</td>
<td><input name="" src="/tab_unsel_right.png" border="0" type="image"></td>
<td width="1"></td>
</tr>
</tbody>
</table>
...
</b></b>
My casper.js file looks like this:
...
casper.then(function() {
test.assertTextExists("DB", "Login into DB 2");
this.click('a#changeThis1_link');
});
casper.then(function() {
test.assertTextExists("Options", "DB Options");
this.click('a#menu1itemUnSel[tabindex="4"]');
});
casper.then(function() {
test.assertTextExists("Change", "DB -Change -Step 1/2");
this.fill('form[name="dbActionForm"]', {
'generalParams.poolSize': '1',
}, false);
this.click('input[name="Apply"]');
});
...
I just can't figure out what should this line look like:
this.click('a#menu1itemUnSel[tabindex="4"]');
since this isn't working!!!
Execution printout:
modifying DB pool size:
Test file: /target.js
# DB modify
PASS DB has the correct title
PASS login form is found
PASS Login into DB
PASS Login into DB 1
PASS Login into DB 2
PASS DB Options
FAIL Cannot dispatch mousedown event on nonexistent selector: a#menu1itemUnSel[tabindex="4"]
# type: uncaughtError
# error: Cannot dispatch mousedown event on nonexistent selector: a#menu1itemUnSel[tabindex="4"]
# CasperError: Cannot dispatch mousedown event on nonexistent selector: a#menu1itemUnSel[tabindex="4"]
# at mouseEvent (/casper.js:1323)
# at click (/casper.js:428)
# at /target.js:34
# at runStep (/casper.js:1523)
# at checkStep (/casper.js:368)
# stack: not provided
Any clue what i am doing wrong and how can i overcome this issue?
Thanks for your time
Some updates and more information:
After Fanch information, I changed the casperjs to:
...
casper.then(function() {
test.assertTextExists("DB", "Login into DB 2");
this.click('a#changeThis1_link');
});
casper.then(function() {
test.assertTextExists("Options", "DB Options");
this.click('a.menu1itemUnSel[tabindex="4"]');
});
casper.then(function() {
test.assertTextExists("Change", "DB -Change -Step 1/2");
this.fill('form[name="dbActionForm"]', {
'generalParams.poolSize': '1',
}, false);
this.click('input[name="Apply"]');
});
...
This a.menu1itemUnSel[tabindex="4"] solved my error about changing the tab but i still have the issue with reading/changing the field generalParams.poolSize.
I even added then waitForSelector/waitForText but still get the error: Errors encountered while filling form: form not found
See casperjs:
...
casper.then(function() {
test.assertTextExists("Options", "DB Options");
this.click('a.menu1itemUnSel[tabindex="4"]');
});
casper.waitForSelector("a#dve_menu_datarepositories", function() {
this.echo("1.Loading form");
});
casper.waitForText("50", function() { //the field that i want to change has text '50'
this.echo("2.Loading form");
});
casper.then(function() {
test.assertTextExists("Change", "DB -Change -Step 1/2");
this.fill('form[name="dbActionForm"]', {
'generalParams.poolSize': '1',
}, false);
this.click('input[name="Apply"]');
});
...
Thanks again
Sorry i was away for a while, here is some html part of the page:
<a name="topofpage">
<form autocomplete="off" enctype="application/x-www-form-urlencoded" action="/db.do" method="post" name="dbActionForm">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr height="100%">
<td valign="top" height="100%"></td>
<td valign="top" height="100%" background="/menu3_sel_right1.png"></td>
<td class="commonfont" width="100%" valign="top" background="/menu3_sel_right1.png" align="left">
<b>
<b>
<table class="commonfont" border="0" cellspacing="0" cellpadding="0" onkeypress="return onWizardPageKeyPress(event);">
<tbody>
<tr id="generalParams.poolSize_TR" class="formpagefieldname" style="display:table-row;">
<td>
<a id="generalParams.poolSize_changeA" style="visibility:hidden;" title="Undo Change" onclick="revertSingleChange('generalParams.poolSize', false); dependantsRunOnLoad(document.body); return false;" href="javascript:;"></a>
</td>
<td>
<input type="text" onblur="if (!this.disabled) {onChangeProperty(this, false);} " onpropertychanged="if (!this.disabled) {onChangeProperty(this, false);} " onkeyup="if (!this.disabled) { onChangeProperty(this, false); }" tabindex="2" title="10" size="30" value="50" name="generalParams.poolSize"></input>
</td>
</tr>
</tbody>
</table>
</b>
</b>
I still have the problem filling in the form!
FAIL Errors encountered while filling form: form not found
# type: uncaughtError
# error: Errors encountered while filling form: form not found
Any clue more?
Thanks for your time!!!
Use this :
this.click('a.menu1itemUnSel[tabindex="4"]');
-> # = div, . = class
Related
I have a SpringBoot application that uses datatables ,
here my datatable on the template
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Position</th>
<th>Actions1</th>
<th>Actions2</th>
</tr>
</thead>
<tbody>
<tbody>
<tr th:each="pic: ${pics}" >
<td class="col_name" >
<div class="box small">
<img th:src="${pic}"/>
</div>
</td>
<td class="col_actions">
<a style="color:#808080; margin-right: 10px;">
<input type="radio" name="${pic}" th:field="*{nadal}" th:value="${pic}" >Nadal<br>
</a>
</td>
<td><button>Delete</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Position</th>
<th>Actions1</th>
<th>Actions2</th>
</tr>
</tfoot>
</table>
and the javascript code on the same page:
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable({
searching: false,
paging: false
}).on("click", "button", function(){
alert('deleting row');
console.log($(this).parent());
table.row($(this).parents('tr')).remove().draw(false);
});
});
</script>
but When I click it makes a server submit of the form
try this:
<script type="text/javascript">
$(document).ready(function() {
const table = $('#example').DataTable({
searching: false,
paging: false
}).on("click", "button", function () {
alert('deleting row');
console.log($(this).parent());
table.row($(this).parents('tr')).remove().draw(false);
});
});
</script>
The easiest way to do whatever you want regardless of the scenario in all programming languages is just create a variable and an if statement. create a Boolean variable in the start and set the value to false. Whenever you want to display something or not display it, just create an if statement saying
if(<name of variable>){
display()
}else{
dontDisplay()
}
You don't have to say === true, you just need to give the variable's name since if you give the name it defaults to true, you only need to say === false for an else if statement.
This works all the time and you can also eliminate false positives, negatives or double alerts in many cases.
I've just inherited a site and have moved a copy to a Windows Server 2008 test server. When I test the login process I'm getting a server error:
405 - HTTP verb used to access this page is not allowed.
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.
I've had a look at the login code and it is using a popover window to show the login form then when it is closed it appears to run jQuery script. This is all happening in the login.html page - here's how it currently looks:
$(document).ready(function() {
$("#myform").validate({
//this is the submit = Log in
submitHandler: function(form) {
$.post('../login.php', $("#myform").serialize(), function(data) {
var theString = (data);
var subString = theString.substr(0, 5);
if (subString == "Error")
//if the string starts with error then, guess what, it's an error!
{
$('#results').html(theString);
} else //open the string as a link, it should be the database entry address returned
{
window.location = theString;
}
});
} //close function(data)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<!-- START ADD THIS FOR LOG IN WINDOW -->
<!-- START Log in window -->
<div id="backgroundPopup"></div>
<div id="popupContact">
<h1> Log In.</h1>
<table width="300" align="center">
<form id="myform" method="POST">
<tr>
<td height="20">
<div align="right"> User Name <input class="" name="username" type="text" size="30" /></div>
</td>
</tr>
<tr>
<td height="20">
<div align="right">Password <input name="password" type="password" size="30" /></div>
</td>
</tr>
<tr>
<td height="5">
</tr>
<tr>
<td align="right" height="20">
<input type="submit" name="action" value="LogIn" class="login_button" />
<!-- class="login_button" style="font-size:11px"
// class="my_password" style="font-size:11px" -->
<!--<a id="popupContactClose">x</a> -->
</form>
</td>
</tr>
<br />
</table>
<div class="error" id="results"> </div>
</div>
<div id="backgroundPopup"></div>
<!-- END Log in window -->
<!-- END ADD THIS FOR LOG IN WINDOW -->
From researching similar issues it appears to be a problem with submitting to a .html page that isn't accepting a POST request, but I can't find the settings to allow this (if this is indeed the actual issue). I can't find any settings so far in the current server that is hosting this successfully without this error message (also running Windows Server 2008).
I'm not looking to make any changes to the code at the moment (e.g. convert to PHP etc) just need to get it running on our test server by allowing a POST request to the login.html page.
My HTML is like this
<tbody>
<tr>
<td ><img src="" alt="close" /></td>
<td><input type="hidden" name="addproducts" value="141420">141420</td>
<td class="prd"><strong></strong></td>
<td><a rel="prettyPhoto" href=""><img src="" alt="Product"></a></td>
</tr>
<tr>
<td ><img src="" alt="close" /></td>
<td><input type="hidden" name="addproducts" value="1213143">1213143</td>
<td class="prd"><strong></strong></td>
<td><a rel="prettyPhoto" href=""><img src="" alt="Product"></a></td>
</tr>
<tr>
<td ><img src="" alt="close" /></td>
<td><input type="hidden" name="addproducts" value="242424">242424</td>
<td class="prd"><strong></strong></td>
<td><a rel="prettyPhoto" href=""><img src="" alt="Product"></a></td>
</tr>
</tbody>
I want select all hidden inputs with name addproducts from this and add to an ajax call.
The problem is that I can't predict how many elements will be there before the code execute.
The ajax url i am trying to make will be like this
http://mydomain.com?addproducts=141420&q141420=16&addproducts=X945X2MG&qX945X2MG=1&addproducts=8382355&q8382355=10&addproducts=146353&q146353=3
my usual code for specific parameters in url will be some thing like this
ajaxManager.add(({
type: 'GET', url: '/ajaxhandler', data: { addproducts: X945X2MG,qX945X2MG:1}
but here i can't use this because of unpredictable parameters.
any way i had made some try which ended up in syntax error.code is this
ajaxManager.add(({
$(this).parent().parent().find(".antal").find("input:hidden[name='addproducts']").map(function () {
return
type: 'GET', data: {addproducts:this.value,'&q'+$(this).val():$(this).next().val()}
EDIT:from Alnitak's post i have tried to edit this .
new code
var data = $(this).parent().parent().find(".antal")
.find("input:hidden[name='addproducts']").map(function () {
return
{ addproducts: this.value}
data['q' + $(this).val()] = $(this).next().val();
}).get().join(',')
ajaxManager.add(({
type: 'GET', data: data
but unfortunatedly it ended up my ajax call comes like this
http://mydomain.com?_=1365768440633
I am sure I have made some thing terribly wrong.Cany one help me on this
You should create an object literal with the known keys, and then use obj[key] syntax for the variable keys:
var data = { 'addproducts[]': [] };
$(this).parent().parent().find(".antal")
.find("input:hidden[name='addproducts']")
.each(function () {
data['addproducts[]'].push(this.value);
data['q' + this.value] = $(this).next().val();
});
$.ajax({
...,
data: data
});
Note the use of addproducts[] to allow encoding of an array of values for that particular parameter. Note that there's not actually a defined standard for passing multiple values with the same key for x-www-form-urlencoded data, but this works with PHP. You should consider changing the way your products are added - perhaps a comma-separated list?
I'm trying to get a specific value from a table cell and pass is to a controller. But it doesn't seem to be working. I show you some of my codes:
This is in the controller:
def searchUser = {
String abc = request.getParameter("harrow")
println(abc)
}
This is in the html page:
<form>
<div style="height: 250px; overflow: scroll; width: 100%;">
<table id="normal">
<g:each in = "${result}">
<tr id="btn">
<td width=10% >${it.ID}</td>
<td width=25% id="harrow">${it.username}</td>
</tr>
</g:each>
</table>
</div>
<input type ="submit" name ="abc" id="opener">
</form>
EDIT
AJAX:
$("#edittable").on('click', function() {
$.ajax({
url: URL,
data: $(this).serialize(),
type: "POST",
success: function(html){
//do something with the `html` returned from the server here
$("#edit1").html(html).dialog("open")
},
error: function(jqXHR, textStatus, errorThrown){
alert('error: ' + textStatus + ': ' + errorThrown);
}
});
return false;//suppress natural form selection
});
I can get the value to pass to the controller, but right now it only retrieves the first row of values rather than the other. Is there something wrong with my AJAX codes? Thank you guys so much.
So to show details of the row, one of the approaches can be:
CONTROLLER METHODS
def rows = [
[id:1, name:'name1'],
[id:2, name:'name2'],
[id:3, name:'name3']
]
def show(){
[results:rows]
}
def showLine(Long id){
render rows.find {it.id == id }
}
VIEW
<html>
<head>
<g:javascript library="jquery" />
<r:layoutResources />
</head>
<body>
<table>
<thead>
<tr>
<th>Action</th>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<g:each in="${results}" status="i" var="r">
<tr>
<td><g:remoteLink value="Details" id="${r.id}" action="showLine" update="lineDetails">Details</g:remoteLink></td>
<td>${r.id}</td>
<td>${r.name}</td>
</tr>
</g:each>
</tbody>
</table>
<div id="lineDetails">
</div>
</body>
</html>
Basically you call showLine method using AJAX and passing row object id. Then you search for the object and render it back. Rendered data is put into div under the table. It's up to you if you use onclick, button or link in the table. It's also up to you how to show details on results page - use jquery dialog, or something else. Hope it helps
I want to create a form (will be filled by users) and store the data in excel stylesheet without using php just HTML ,is that possible?
I dont want to store data an a database.
I have tried to use google doc but it's not that good because the validation messages are generated depending on the browser language.
The unqualified response of "You can't write a file from HTML" is inaccurate. While you may need to add some "hidden" fields in your HTML (in order to simplify the exporting of only the data requested and not the questions or other text) it is ABSOLUTELY possible to do this. I've done JUST THAT in the code below - and all I use is JavaScript. No Server required, No Database required, No PHP required.
Below is the code and a link to the JSFiddle page where you can see it in action:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fillHidTable(){
var htqf; //-- hidden field
var rf; //-- retrieved field
for ( var i = 1; i < 5; i++ ) {
rf = "htqf"+i;
document.getElementById(rf).innerHTML = document.getElementById("Q"+i+"CALC").value;
}
tableToExcel('hidTable', 'Analysis Results');
}
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
<title>HTML Form Data to Excel</title>
<style type="text/css" media="screen">
.divCenMid{font-family:Arial,sans-serif;font-size:14pt;font-style:normal;font-weight:700;text-align:center;vertical-align:middle;margin:0;}
.allbdrCenMid{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:center;vertical-align:middle;margin:0;}
.allbdrCenTop{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:center;vertical-align:top;margin:0;}
.allbdrLtMid{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:left;vertical-align:middle;margin:0;}
.allbdrLtTop{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:left;vertical-align:top;margin:0;}
</style>
</head>
<body>
<table width= "565px" cellspacing="0" cellpadding="0" style="border-spacing:0;" id="QMSTable">
<col width="25px"/>
<col width="120px"/>
<col width="360px"/>
<col width="60px"/>
<tr>
<td class="divCenMid" colspan = "4"> QMS Assessment</td>
</tr>
<tr>
<td class="allbdrCenMid"> No</td>
<td class="allbdrCenMid"> Criteria</td>
<td class="allbdrLtMid"> Question</td>
<td class="allbdrCenMid"> Score</td>
</tr>
<tr>
<td class="allbdrCenTop"> Q1</td>
<td class="allbdrLtTop"> Quality Unit Independency</td>
<td class="allbdrLtTop"> Do you have the Quality Unit?</td>
<td class="allbdrCenMid">
<input id="Q1CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q1CALC"/>
</td>
</tr>
<tr>
<td class="allbdrCenTop"> Q2</td>
<td class="allbdrLtTop"> Apply PICS GMP</td>
<td class="allbdrLtTop"> Which GMP regulation do you use?</td>
<td class="allbdrCenMid">
<input id="Q2CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q2CALC"/>
</td>
</tr>
<tr>
<td class="allbdrCenTop"> Q3</td>
<td class="allbdrLtTop"> Deviation or Non-conformance</td>
<td class="allbdrLtTop"> Do you have a deviation or non-conformance procedure?</td>
<td class="allbdrCenMid">
<input id="Q3CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q3CALC"/>
</td>
</tr>
<tr>
<td class="allbdrCenTop"> Q4</td>
<td class="allbdrLtTop"> Complaint</td>
<td class="allbdrLtTop"> Do you have a customer complaint procedure?</td>
<td class="allbdrCenMid">
<input id="Q4CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q4CALC"/>
</td>
</tr>
</table>
<div id="hidTable" style="display: none">
<table id="testTable">
<caption>Supplier Risk Analysis</caption>
<colgroup></colgroup>
<colgroup></colgroup>
<colgroup></colgroup>
<thead>
<tr>
<th>No.</th>
<th>Question</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1</td>
<td>Do you have the Quality Unit?</td>
<td id="htqf1">-</td>
</tr>
<tr>
<td>Q2</td>
<td>Apply PICS GMP?</td>
<td id="htqf2">-</td>
</tr>
<tr>
<td>Q3</td>
<td>Do you have a deviation or non-conformance procedure?</td>
<td id="htqf3">-</td>
</tr>
<tr>
<td>Q4</td>
<td>Do you have a customer complaint procedure?</td>
<td id="htqf4">-</td>
</tr>
</tbody>
</table>
</div>
<input type="button" onclick="fillHidTable()" value="Export Data to Excel">
</body>
</html>
Here is the JSFiddle link: https://jsfiddle.net/MitchinThailand/LV9vr/
if you want more details feel free to holler.
No, HTML pages cannot write files. You need a server to do this.
The best you can do is generate CSV data in a textarea that the user could then copy and paste to a local file, then load that into Excel.
As it is not possible to save html form data to a file using javascript because of some security reason so for my solution i just use the TCPDF for this.
You can generate a data: URL with the download attribute:
<a download="test.csv" href="data:text/csv,foo,bar,baz">
You'll need to use JavaScript to build such URL from form data and insert/update appropriate link in the document.
To do what you want to do simply it will not be possible without php or some advanced HTML5 local storage.
I've done this by using simple PHP script to have form data get saved to a .txt file and then open the resulting .txt file in Excel and use the text to columns feature.
I have a HTML form which collects a field where people enter their email address. I want the form to post the email address to a text file. Please help! Will award maximum points to the one who will answer me correctly!
2 years ago Report Abuse
Additional Details
Please paste entire code to do this!
2 years ago
Form:
<form method="post" action="nameofyourscripthere.php">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email" />
<input type="submit" name="submit" value="Send Form" />
</form>
PHP:
Create a new page saved as .php with this code. All you need is the form and the PHP script on the server for this to work :)
<?php
// Get the name they entered in the form
// We'll be naming the file this
$file = $_POST['name'];
// Get the email from the form
$email = $_POST['email'];
// We want the file to be a text file right?
$ex = ".txt";
// Try to open a file named $file$ex (johndoe.txt for example)
// Because this file doesn't exist yet the server creates it
$write = fopen("$file$ex","w");
// Now open the file up again but this time save the email in it
fwrite($write,$email);
// MAKE SURE you close the file!!!
fclose($write);
// The folder that this script is in on the server is where the file we just made was saved
// We can 'rename' it to another folder
// The folder on the server we want to move it to
$data = "../emails/";
// Now put it all together: This example goes out of the folder we're in and into the folder 'emails'
// The new 'name' would be this now (../emails/johndoe.txt): So now the file is moved to where we want for storage
rename ("$file","$data$file$ex");
// The script is done, send the user to another page (Just read the address below and you'll get it)
// Its just an example fyi change to what you want
header('Location: http://YourWebsiteNameHere.com/contactFo…
exit;
?>