How can I automate the task of populating values in handsontable using Watir?
I have list of values in excel. Watir reads these values and then populates handsontable in their respective column. The challenge is none of the fields in handsontable has an identification property, which makes the job more difficult.
Pls find HTML Code as requested:
<html>
<head>
<body>
<form action="importer.php" method="POST">
<div class="selections">
<div id="buildingSelector" style="display: none;">
<script src="js/importer/buildingselect.js">
<script type="text/javascript">
<div id="importdata" class="handsontable">
<div class="wtHolder" style="position: relative; display: table;">
<div class="wtHider" style="position: relative; overflow: hidden; width: 1904px;">
<div class="wtSpreader">
<table class="htCore" style="display: table;">
<colgroup>
<thead>
<tr>
<thead>
<tbody>
<tr>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
Related
I am working on an API which generates a pdf document based on an EJS template which then gets emailed to some users. When running Locally everything works as expected however when my API is pushed to heroku the pdf is generated with some odd formatting errors. Its like the page is essentially cut down the middle vertically.
Does anyone know a possible cause of this?
I am using ejs, and html-pdf
Here is the code and template
document generation function
ejs.renderFile(path.join(__dirname, '../views/', "offer.ejs"), {offerData}, (err, data) => {
if(err)
reject(err)
else
{
const options = {
"height": "11.25in",
"width": "8.5in",
"header": {
"height": "10mm"
},
"footer": {
"height": "10mm",
}
};
//creates the actual pdf doc for sending
pdf.create(data, options).toFile(`./offer_${inqID}.pdf`, function(err, res) {
if (err)
reject(err)
else
resolve(res.filename)
});
}
});
html pdf template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trade-in Disclosure Form</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/css/bootstrap.min.css" integrity="sha384-VCmXjywReHh4PwowAiWNagnWcLhlEJLA5buUprzK8rxFgeH0kww/aWY76TfkUoSX" crossorigin="anonymous">
<style>
body{
font-family: 'Roboto', sans-serif !important;
}
h1{
text-decoration: underline !important;
}
table.center {
margin-left:auto;
margin-right:auto;
}
td.rows{
padding-bottom: 10px;
text-align: left !important;
}
td.question{
padding-right: 15px;
}
span{
font-weight:bold !important;
}
</style>
</head>
<body style="border: solid black 2px; margin-left: 10px; margin-right:10px;">
<header class="text-center">
<h1 >The Auto Broker</h1>
<h2> Trade-In Vehicle Disclosure Form</h2>
<p style="margin-left: 6em; margin-right: 6em">
This Form has been filled out by the customer requesting a quote. It contains some basic details to help inform your evaluation of the vehicle.
If the customer provides false information you have the right to recind or adjust your offer to the customer; otherwise include the value of
this vehicle in your total value for the quote. Please ensure to carefully review all the data before providing a quote. Quotes are final and
cannot be altered once submitted.
</p>
</header>
<div style="padding-top:20px;">
<div class="form-container container">
<div class="row" style="background-color: black;">
<h3 style="color: aliceblue;" class="ml-2"> Vehicle History</h3>
</div>
<table class="center">
<thead>
<tr>
<th style="padding-bottom: 20px;"> <h4>Question </h4></th>
<th style="padding-bottom: 20px;"> <h4>Response </h4></th>
</tr>
</thead>
<tbody>
<tr>
<td class="rows question">Has the Vehicle been in an accident?</td>
<td class="rows"> <%= questionnaire.inaccident %> </td>
</tr>
<tr>
<td class="rows question">Have any panels been repainted, repaired <br> or replaced?</td>
<td class="rows"> <%= questionnaire.panelrepairs %> </td>
</tr>
<tr>
<td class="rows question">Are you the original owner?</td>
<td class="rows"> <%= questionnaire.originalowner %> </td>
</tr>
<tr>
<td class="rows question">Is this an American Vehicle?</td>
<td class="rows"> <%= questionnaire.usvehicle %> </td>
</tr>
<tr>
<td class="rows question">Has the Vehicle been registered in any other <br> Province/State?</td>
<td class="rows"> <%= questionnaire.outofprovreg %> </td>
</tr>
<tr>
<td class="rows question">Is the Odometer faulty, replaced or rolled back? </td>
<td class="rows"> <%= questionnaire.faultyodometer %> </td>
</tr>
<tr>
<td class="rows question">Does the vehicle have any lights on the dashboard?</td>
<td class="rows"> <%= questionnaire.dashlights %> </td>
</tr>
<tr>
<td class="rows question">Does the vehicle have any factory warranty?</td>
<td class="rows"> <%= questionnaire.factorywarranty %> </td>
</tr>
<tr>
<td class="rows question">Does the vehicle have extended warranty?</td>
<td class="rows"> <%= questionnaire.extwarrenty %> </td>
</tr>
<tr>
<td class="rows question">Was the vehicle ever used as a daily rental, <br> police vehicle, or taxi/limousine?</td>
<td class="rows">
<% if (questionnaire.rental) { %>
Rental <br>
<% } %>
<% if (questionnaire.taxilimo) { %>
Taxi / Limo <br>
<% } %>
<% if (questionnaire.policecar){ %>
Police Vehicle <br>
<% } %>
</td>
</tr>
<tr>
<td class="rows question">Does the vehicle require repairs to the following: <br>
<span style="margin-left: 10px;">Engine </span> <br>
<span style="margin-left: 10px;">Transmission/Powertrain</span> <br>
<span style="margin-left: 10px;">Electrical System </span> <br>
<span style="margin-left: 10px;">Air Conditioning System</span>
</td>
<td class="rows">
<%= questionnaire.enginerepair %> <br>
<%= questionnaire.transrepair %> <br>
<%= questionnaire.electricalrepair %> <br>
<%= questionnaire.acrepairs %> <br>
</td>
</tr>
<tr>
<td class="rows question">Additional Repair Details</td>
<td class="rows"> <%= questionnaire.repairdetails %> </td>
</tr>
<tr>
<td class="rows question">Outstanding Balance</td>
<td class="rows">
<% if (questionnaire.outstandingbalance){ %>
<%= questionnaire.outstandingbalance %>
<% } %>
</td>
</tr>
<tr>
<td class="rows question">Total Current Milage</td>
<td class="rows"> <%= questionnaire.milage %> K.M </td>
</tr>
<tr>
<td class="rows question">V.I.N</td>
<td class="rows"> <%= questionnaire.vin %> </td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
Proper Img
Broken Img
Was able to solve this issue by adding a single CSS style Rule.
html {
zoom: 0.55;
}
This is most likely required due to the default zoom setting of the html-pdf package. This setting and more can also be configured with options; however, i am unsure if the zoom options can be configured to < 1.
I'm facing the same prblm. I think u have to use inline CSS... u can't use bootstrap. I was facing the same problem. but now it is ok with puppeteer
I want to know what to get some content not include quote content.
The following url is the target webpage:
https://forumd.hkgolden.com/view.aspx?type=BW&message=7219211
I must use a full xpath to get their content. I want to get black color content and I don't want to get blue content, but when I use the following code. I got blue and blank content together.
content = driver_blank.find_element_by_xpath('/html/body/form/div[5]/div/div/div[2]/div[1]/div[5]/table[8]/tbody/tr/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/div')
print(content.text)
The following is their html code:
<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 7px;">
<tbody>
<tr>
<td align="left">
<table class="repliers">
<tbody>
<tr hc7uwnfktbez9="" id="XoBTa" userid="461194" username="浅川梨奈">
<td class="repliers_left" style="background-color: #F3F2F1;">
<div>
<a name="275220714"></a>
<a href="javascript: ToggleUserDetail(6, 'XoBTa');" style="font-weight: bold; color: #FF0066;">
浅川梨奈
</a>
<br>
<br>
<div id="ThreadUser6" style="position: relative;">
<a href="/ProfilePage.aspx?userid=461194" style="text-decoration: none;">
<img src="/icons/97.gif" style="border-width: 0px;" alt="Logo">
</a>
<br>
<br>
<img src="/labels/4.gif" style="border-width: 0px;" alt="Member">
</div>
</div>
</td>
<td style="background-color: #F3F2F1; height: 100%; border: solid 1px #111111; vertical-align: top;">
<table class="repliers_right" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<div class="ContentGrid">
<blockquote><div style="color: #0000A0;">有冇第隻款<img data-icons=":-[lm" src="/faces/lomore/angry.gif" alt=":-[lm"> <img data-icons=":-(lm" src="/faces/lomore/frown.gif" alt=":-(lm"> 我想要呢兩隻</div></blockquote>
<br>
係囉,反應好既會唔會考慮出其他?
<br>
我都想要其他
<img data-icons="^3^lm" src="/faces/lomore/kiss.gif" alt="^3^lm">
<img data-icons="[bomb]lm" src="/faces/lomore/bomb.gif" alt="[bomb]lm">
<br><br><br>
</div>
</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: top;">
<div id="lineImage6" style="display: block; overflow: hidden;">
</div>
</td>
</tr>
<tr>
<td style="width: 100%; text-align: right;">
<div style="float: right; vertical-align: bottom; margin-top: 5px;">
<div id="lauming6" style="float: left; vertical-align: bottom;"></div>
<a class="btn btn_small btn_bookmark" href="Javascript:bookmarkThis(7219211)" id="laumingHref">留名</a>
<a class="btn btn_small btn_complain" href="contactus.aspx?messageid=7219211&replyid=275220714">投訴文章</a>
<a class="btn btn_small btn_quote" href="Javascript:QuoteReply(7219211,275220714);">快速引用</a>
<a class="btn btn_small btn_quote" href="post.aspx?mt=Y&rid=275220714&id=7219211&page=2">引用原文</a>
<span style="font-size: 12px; color:gray;">
15/4/2020 13:18
</span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I hope to use start-to, not, or contains instruction to finish it.
Can anyone help me? Thanks~~~
#QHarr answered my question here Get the value inside Nested Tables and Divs using VBA regarding the values inside the nested tables and it worked great. Now I realize that not all the data are getting pulled. Here is what I thought my HTML was:
<body style="BORDER: 0px; MARGIN: 0px; PADDING: 0px">
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
// This TD was solved by #QHarr
<TD ID="oReportCell">
Some tables and values. #QHarr already solved this part
</TD>
</TR>
</TABLE>
</DIV>
</body>
But when I realized that not all the data were pulling I checked the HTML I found out that not all the data are inside the ID="oReportCell"
So, HTML looks like this:
<body style="BORDER: 0px; MARGIN: 0px; PADDING: 0px">
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
// This TD was solved by #QHarr
<TD ID="oReportCell">
Some tables and values. #QHarr already solved this part
</TD>
</TR>
</TABLE>
</DIV>
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ID="oReportCell">
Some tables and values.
</TD>
</TR>
</TABLE>
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ID="oReportCell">
Some tables and values.
</TD>
</TR>
</TABLE>
</body>
They are 14 of Class="ap", and when the code is executed sometime it gets the first one. Sometime the second and so on. It doesn't get all the value.
I need to get everything that is inside class ="a92" and class="a69"
here is the full html:
I can't use pastebin due to the size of the file:
enter link description here
here is one of the .ap
enter link description here
I am trying to extract html code from a div:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="tbParams">
<table class="ParametrList" style="border-collapse: collapse; width: 100%;">
<tr class="Parametr altrow">
<td class="Nazev">
Hello </td>
<td class="Hodnota" style="vertical-align: top;">
</td>
</tr>
</table>
</div>
</body>
</html>
...with xidel:
xidel input.html -e '//div[#id="tbParams"]' --output-format html
For some reason it keeps adding XMLNS attributes to the output:
<div xmlns="http://www.w3.org/1999/xhtml" id="tbParams">
<table class="ParametrList" style="border-collapse: collapse; width: 100%;">
<tbody xmlns=""><tr xmlns="http://www.w3.org/1999/xhtml" class="Parametr altrow">
<td class="Nazev">
Hello </td>
<td class="Hodnota" style="vertical-align: top;">
</td>
</tr>
</tbody></table>
</div>
If I remove xmlns="http://www.w3.org/1999/xhtml" from the <html> tag, then it is OK.
I have a table containing multiple columns in which the data is populated from a database. The columns can have drop-downs, text-fields, check-boxes along with simple text. I need to write down a function which will essentially return the data present in a table column.
Here's an example as to how the tags are named in the web page. [Credits to w3schools for the CSS for the tables].
<html>
<head>
<style type="text/css">
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr class="data-row">
<td id="customers:0:company">Alfreds Futterkiste</td>
<td id="customers:0:contact">Maria Anders</td>
<td id="customers:0:chooseCountry">
<select id="customers:0:country">
<option>Germany</option>
<option>Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row alt">
<td id="customers:1:company">Berglunds snabbköp</td>
<td id="customers:1:contact">Christina Berglund</td>
<td id="customers:1:chooseCountry">
<select id="customers:1:country">
<option>Germany</option>
<option selected="selected">Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row">
<td id="customers:2:company">Centro comercial Moctezuma</td>
<td id="customers:2:contact">Francisco Chang</td>
<td id="customers:2:chooseCountry">
<select id="customers:2:country">
<option>Germany</option>
<option>Sweden</option>
<option selected="selected">Mexico</option>
</select>
</td>
</tr>
</table>
</body>
</html>
Now, the algorithm which I use for determining all the values in the column say "Company" is
Determine the no of rows having class = or substring as "data-row".
Construct the string for getting the cell and iterating it from 0 to n-1
Use the text method to retrieve the text
Now, if I use this on a select_list, it returns all the options in the list. Thus, I was going to check whether the child of the tag is either a text-field or a drop-down
list and call their respective functions to get their values.
Is there a way where in Watir we can determine the child of a particular tag is a particular tag or not or is there some method similar to getAllChildNodes in JavaScript?
Sorry for being over-descriptive and thanks in advance for any possible solutions.
This is very simple, you just need to see whether a text_field or select_list exists:
require 'watir-webdriver'
b = Watir::Browser.start 'yourwebpage'
b.table.rows.each do |row|
row.cells.each do |cell|
if cell.text_field.exist?
puts cell.text_field.value
elsif cell.select_list.exist?
puts cell.select_list.selected_options
else
puts cell.text
end
end
end
b.close