Is there a way to transpose a table which is filled using Vue?
The html now is:
<table>
<tr>
<th>Date</th>
<th>Temp(max)</th>
<th>Temp(min)</th>
<th>Rain</th>
<th>Icon</th>
</tr>
<tr v-for="forecast in forecasts">
<td>{{forecast.date}}</td>
<td>{{forecast.maxTemp}}°C</td>
<td>{{forecast.minTemp}}°C</td>
<td>{{forecast.rain}} mm</td>
<td><i :class="translateIcon(forecast.icon)"></i></td>
</tr>
</table>
But I want to change this table view to have the dates in Row 1, the max temp in Row 2, etc.
Related
Scenario: I have a table where I am trying to iteratively go through each row that matches my expected text and grab a particular column value for that row.
The html looks something like this:
<table class="table">
<tbody>
<tr xpath="1">
<td>
Write
</td>
<td>
123
</td>
<td>
1.0.1.8
</td>
<td>
TargetProduct1
</td>
<td>
</td>
<td>
P1
</td>
<td>
10.0
</td>
<td>
en-US
</td>
<td>
</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
</table>
On that table, my goal is to go through each row and pick any row that has the value of "TargetProduct" and get the fifth column value of that row.
I am using the following Karate command:
* def getProduct = scriptAll('//table//tbody//tr', '_.innerText', function(x){ return x.contains('TargetProduct') })
However, when I do a karate.log on getProduct, I get something like the following:
Write 123 1.0.1.8 TargetProduct1 P1 10.0 en-US
Write 4586 1.0.1.3 TargetProduct5 Test2 10.1 en-US
Write 134 1.0.1.1 TargetProduct0 Four2 10.3 en-US
Write 3 1.0.1.2 TargetProduct2 Boo3 10.1 en-US
Along with many more like it under it (due to each row that matches the criteria).
It looks like primitive data structure, but I am not well versed in JS to know that. However, my goal is to grab the 5th index of each sets of results like above (basically generate a list with just these values: (P1, Test2, Four2, Boo3). What is one way to do that? Historically I have been able to get values using keys (i.e targetJson.result). However, there are no keys in this case to call to.
I have looked over JSON Transforms section of the documentation and I have tried some potential solutions like mapWithKey, however, they have not worked due to the strange data structure.
Please advise.
You could return an array from the JavaScript expression, containing a first value for filtering and a second string containing the text from your fifth column.
* def filter = function(x){ return x[0].contains('TargetProduct') }
* def rows = scriptAll('//table//tbody//tr', 'function(e){ return [e.innerText, e.cells[4].innerText] }', filter)
* def fifthCols = map(rows, function(x){ return x[1] })
First, read up on innerText to see what it does: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText - it just returns a single string, concatenating all child elements.
Suggestion: try to do this in multiple steps:
* def rows = locateAll('//table//tbody//tr')
* def filtered = rows.filter(x => x.text.includes('TargetProduct'))
* def temp = filtered.map(x => x.locateAll('td'))
What I have above is a guess, sorry I don't have time to dig into the details.
HTML:
<div class="attach">
<app-table>
<table class="table"> //
<thead>
<tr>
<th><span>Name</span></th>
<th><span>Address</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>aaa</td>
<td>bbb</td>
</tr>
<tr>
<td>aaa111</td>
<td>bbb222</td>
</tr>
</tr>
</tbody>
</table>
</app-table>
</div>
The page may have multiple web tables. However, parent element "attach" is unique for this table.
How can I count the total number of rows and columns? I found lot of info online but I could not fix it.
from www.tutorialspoint.com/how-to-count-the-number-of-rows-in-a-table-in-selenium-with-python:
# identifying the number of rows having <tr> tag
rows = driver.find_elements_by_xpath("//table/tbody/tr")
# len method is used to get the size of that list
print(len(rows))
#to close the browser
driver.close()
Number of cells may vary per row. But you can use xpath to count those too:
row1 = driver.find_elements_by_xpath("//table/tbody/tr")
cols = row1.find_elements_by_xpath("//td")
print(len(cols))
You have include the class name in the xpath to make it unique in your case.
#Number of columns in the table
cols = driver.find_elements_by_xpath("//div[#class="attach"]//table/thead//th")
print(cols)
#Number of rows in the table
rows = driver.find_elements_by_xpath("//div[#class="attach"]//table/tbody//tr")
print(rows )
We can resolve this in Java Language as follows:
List rows=driver.findElements(By.xpath("//div[#class="attach"]//tbody//tr"));
int rowCount=rows.size();
List columns=driver.findElements(By.xpath("//div[#class="attach"]//table//th"));
int columnCount=columns.size();
So I am posting this after seraching alot of SO queries and answers.
I have a table that gives the booktime, pickup time. I want to calculate the average timedifference between the two timestamps group on hourly basis and area-wise.The desired output is given below
This all needs to be done in SQL
<table>
<tr>
<td>Hour</td>
<td>Order#</td>
<td>AverageResponseTime</td>
</tr>
<tr>
<td>1</td>
<td>20</td>
<td>15:13</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>02:45</td>
</tr>
<tr>
<td>3</td>
<td>120</td>
<td>01:20</td>
</tr>
<tr>
<td>24</td>
<td>10</td>
<td>19:05</td>
</tr>
</table>
Try this-
select
AreaName,
datepart(hour, BookTime) as BookTimeHour,
(AVG(Datediff(second, booktime, pickuptime))/60.0) as AvgTimeInMinutes
from #MyTable
group by
AreaName,
datepart(hour,BookTime);
I have a table with a few columns. I want to get data from two of the columns; email and URL.
One column being email. I want distinct emails.
The second column is a url. I want to get only the urls that match what I'm looking for, for example, xyz.
So the table looks like this:
<table>
<tbody>
<tr>
<td>Email</td>
<td>URL</td>
</tr>
<tr>
<td>user#yahoo.com</td>
<td>xyz</td>
</tr>
<tr>
<td>user#gmail.com</td>
<td>abc</td>
</tr>
<tr>
<td>user#outlook.com</td>
<td>xyz</td>
</tr>
<tr>
<td>user#email.com</td>
<td>xyz</td>
</tr>
</tbody>
</table>
How do I execute a query so that only the emails from the xyz url are found?
Unless I’m missing something, you just need to do:
Select Distinct Email
From YourTable
Where URL = 'xyz'
I have 2 sections in a database. Drafts and Albums. So we get a draft for an album. The drafts have requirements, and later an album is created. That album also has requirements, but the requirements on both sides are entered independently. Some will change, be dropped, new ones added, etc. I am trying to make a query to compare those requirements, when an album is assigned as having coming from a specific draft.
The table structure looks like this:
Drafts:ID, draft fields
Draft Requirements: ID, Draft FK, Requirement Type FK
Albums: ID, Drafk FK (not required immediately, but will only be able to audit against a draft, if this is not null), album fields
Album Requirements: ID, Album FK, Requirement Type FK
So I want to create a query with the following:
Draft Fields, Album Fields, Draft Requirements, Album Requirements
Basically if there are 10 requirements it would look like this (excuse the code, wanted to try to make a table, so you can really see):
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-yw4l">Draft Req</th>
<th class="tg-yw4l">Album Req</th>
</tr>
<tr>
<td class="tg-yw4l">R1</td>
<td class="tg-yw4l">R1</td>
</tr>
<tr>
<td class="tg-yw4l">R2</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l">R3</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l">R4</td>
</tr>
<tr>
<td class="tg-yw4l">R5</td>
<td class="tg-yw4l">R5</td>
</tr>
<tr>
<td class="tg-yw4l">R7</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l">R8</td>
</tr>
<tr>
<td class="tg-yw4l">R9</td>
<td class="tg-yw4l">R9</td>
</tr>
</table>
This is the first part of the query, with just basic info for the draft and album:
SELECT vw_CMP_Contacts.ContactNo, vw_CMP_Contacts.ContactName, vw_CMP_Matches.MatchNo, vw_CMP_Matches.MatchName,
tblContactDraft.txtOrganization, tblDraftStatus.txtDraftStatus, tblMAlbumStatus.txtAlbumStatus, tblAlbumType.txtAlbumType
FROM ((((vw_CMP_Matches
INNER JOIN (tblMAlbums INNER JOIN tblContactDraft ON tblMAlbums.FKContactDraft = tblContactDraft.ID) ON vw_CMP_Matches.CM_MID = tblMAlbums.FKMatch)
INNER JOIN tblDraftStatus ON tblContactDraft.FKDraftStatus = tblDraftStatus.ID)
INNER JOIN tblMAlbumStatus ON tblMAlbums.FKMAlbumStatus = tblMAlbumStatus.ID)
INNER JOIN tblAlbumType ON tblMAlbums.FKAlbumType = tblAlbumType.ID)
INNER JOIN vw_CMP_Contacts ON vw_CMP_Matches.ContactNo = vw_CMP_Contacts.ContactNo
Next I have to join the draft requirements, by draft fk, to tbldraftreqs, and req type by fk req type. I have the same for albums in an tblalbumreqs.
when i try to join those, I get no results, even though both have requirements. The issue is, i'm directly joining drafts to albums, but then I need both requirements, and for them to line up together or alone, depending on if they both have the same requirement.
Make sense?
I'd love any pointers in solving this conundrum!
I figured it out. There is only so much I can explain about a question. If the only comments are to complain that I didn't explain enough, I'll just keep researching on my own.
Anyway, I hope this helps someone else trying to do the same kind of joining.
SELECT mc.ID as mcid, mc.FKContactDraft as Draftid, rq.ID, rq.txtRequirementType, Draft.FKRequirementType AS DraftReq, cont.FKRequirementType AS MCReq
from tblMAlbums mc
full join tblReqType rq on 1=1
left join tblContactDraftRequirements Draft on mc.FKContactDraft = Draft.FKContactDraft and rq.ID = Draft.FKRequirementType
left join tblMAlbumRequirements cont on mc.ID = cont.FKMC and rq.ID = cont.FKRequirementType
where mc.FKContactDraft is not null