I got a question.
i have tha following foreach loop:
{foreach from=$films item=film key=id}
<tr>
<td>
{$film.filmtitel}
</td>
<td>
{$film.zaaltitel}
</td>
<td>
plaats {$film.stoeltjes}
</td>
<td>
{$film.dag}
</td>
<td>
{$film.tijdstip}
</td>
<td>
5€
</td>
<td>
<a href="?page=winkelwagentje&action=verwijder&id={$smarty.forach.id.index}">
<img src="images/verwijderButton.png" alt="verwijderButton" title="verwijderButton"/></a>
</td>
</tr>
{/foreach}
these represent various items. now when its displayedin the browser the link gives me the url, ending with:
id=0 then the next is id=1 and so on.
When i remove 1 of these items through a button, the id's automaticly get rearranged so the index starts back with 0, then 1 and so on. What i would like to have is that if for instance i remove item with id=1 and the page gets refreshed, the id should remain deleted.
So the urls would look like:
id=0
id=2
id=3
anyone know if this is possible?
I understand your problem. You could rely on the keys of the array, but in this case you should populate the array in the same order and with the same id. It seems for me that this is a result set from a database table. It would be much easier to rely on an id of the database table which has unique values.
btw. you have a typo in your example code (...id={$smarty.forach...)
Related
I want to search Seller and have to click on select link for selected one. When I type seller name, it shows only record for selected seller.
I tried with following code, its not working. Can anyone please help
cy.get('input[name="search"]',{ timeout: 10000 }).type(this.data1.vehicle1_seller1)
//cy.wait(6000)
Cypress.config('defaultCommandTimeout', 10000);
cy.get('td[class="span-3"] div').each(($el, index, $list) => {
if ($el.text().includes('STB002')) {
// cy.contains("Select").eq(index).click()
cy.get('.span-1-5 > div > a > span').contains('select').eq(index).click({force:true})
}
}
this is the DOM structure >
<table>
<tbody>
<tr class="even">
<td class="span-3">
<div title="06V001">06V001</div> == $0
</td>
<td>
<div title="06 Vauxhall Ormskirk">06 Vauxhall Ormskirk</div>
</td>
<td class="span-1-5">
<div>
<a id="link57" href="./wicket/page?7-1.-seller-table-body-rows-10-cells-3-cell-link">
<span>select</span>
</a>
</div>
</td>
</tr>
<tr class="odd">
</tr>
<tr class="even">
</tr>
</tbody>
</table>
The HTML table is set out in rows and cells, exactly as you see it on the screen.
Your test is searching for the cell containing the text, but really you want to search for the row containing the text, then get the select button of that row.
The basic test would be
cy.contains('tr', 'STB002')
.within(() => {
// now inside the row
cy.contains('span', 'select').click()
})
The next problem is the car STB002 isn't on the first page, so you won't find it straight after loading.
Maybe use the search box to load that row (as you have in one screen-shot). I can't say what that code is, because the DOM picture doesn't include the search box.
I have the follow html file:
<table class="pd-table">
<caption> Tech </caption>
<tbody>
<tr data-group="1">
<td> Electrical </td>
<td> Design </td>
<tr data-group="1">
<td> Output </td>
<td> Function </td>
<tr data-group="7">
<td> EMC </td>
<table>
<tbody>
<tr>
<td> EN 6547 ESD </td>
<td> EN 8901 ESD </td>
<tr data-group="8">
<td> Weight [8] </td>
<td> 27.7 </td>
I can isolate EN 6547 ESD and EN 8901 ESD with the follow xpath:
//table[#class="pd-table"]//tbody//tr//td/table//tr//td/text()').getall()
Any other way is always welcome :)
Another data which I would like to get is to get all the rest of the data without the previous isolated.
Is there any way to do it? :)
Looks like table tag is not closed properly in data-group-7...
Anyway in such cases you can stick to text content of the cell using contains() or text()="some exact text"
response.xpath('//td[contains(text(), "EMC")]').css('td~table tbody td::text').extract()
Your used Xpath uses a lot of unwanted double slash.
See meaning of double slash in Xpath.
The less you use double slash, the better it will perform.
So just use single slash like this:
//table[#class="pd-table"]/tbody/tr/td/table/tr/td/text()
Another way of selecting td's that have two ancestor::table
//td[count(ancestor::table)=2]/text()
And that leads to the answer of your second question:
//td[count(ancestor::table)=1]/text()
An other possibility would just be:
//table[#class="pd-table"]/tbody/tr/td/text()
Or(assuming the second tabel does not have tr's with #data-group):
//tr[#data-group]/td/text()
So you see there are many Xpath's lead to Rome ;-).
Have a table with the filtering and sorting like so:
<tbody>
<tr class="row"
repeat.for="repo of repos |
filter:searchField.value:filterGitHubTable |
sort: {propertyName: column.value, direction: direction.value} |
pageData:{currentPage: pageNumber, pageSize:pageSize}">
<td class="col-xs-3">${repo.name}</td>
<td class="col-xs-3">${repo.stargazers_count}</td>
<td class="col-xs-3">${repo.forks_count}</td>
<td class="col-xs-3">${repo.open_issues}</td>
</tr>
</tbody>
In my pager code below its setup as
<pagination model.bind="repos"
page-size.bind="pageSize"
pageclick.delegate="handlePageClick($event)"
pagination-class="pg-bluegrey"></pagination>
How to make the pagination element model bind to the reference of a filter result 'after the sorting' but 'before it does the next filter for pagination data'?
The reason is once have pagination data, I don't have the whole filter result to bind with the pagination element. How would I keeping track of page numbering when applying the filter on the table result?
Here's a little trick you might be able to use here. You can use a hidden HTML element to sort of "hold on" to an intermediate version of your data. Aurelia allows you to attach arbitrary attributes to any element, and by using the ref attribute, we can attach the element itself to our viewmodel. We can then access any data we've attached to this element anywhere we want in our view or viewmodel. Check this out:
<input type="hidden" ref="filteredAndSorted"
data.bind="repos |
filter:searchField.value:filterGitHubTable |
sort: {propertyName: column.value, direction: direction.value}" />
<table>
<tbody>
<tr class="row" repeat.for="filteredAndSorted.data |
pageData:{currentPage: pageNumber, pageSize:pageSize}">
<td class="col-xs-3">${repo.name}</td>
<td class="col-xs-3">${repo.stargazers_count}</td>
<td class="col-xs-3">${repo.forks_count}</td>
<td class="col-xs-3">${repo.open_issues}</td>
</tr>
</tbody>
</table>
<pagination model.bind="filteredAndSorted.data"
page-size.bind="pageSize"
pageclick.delegate="handlePageClick($event)"
pagination-class="pg-bluegrey">
</pagination>
I'm betting this is what will help you. Sorry it took so long to answer, I've been quite busy the last few days doing Aurelia training.
Consider the below table structure contains many rows with multiple column values. I need to identify the parent of specific row, which has to be identified using the cell .
<table class = 'grid'>
<thead id = 'header'>
</thead>
<tbody>
<tr>
<td>
<span class="group">
<span class="group__link"><a class="disabledlink"">copy</a>
</span>
</span>
</td>
<td class="COLUMNNAME">ACE</td>
<td class="COLUMNLONGNAME">Adverse Childhood Experiences</td>
<li>Family Medicine</li>
<li>General Practice</li>
</td>
<td class="COLUMNSEXFILTER">Both</td>
<td class="COLUMNAGEFILTERMIN">Any</td>
<td class="COLUMNTYPE">Score Only</td>
</tr>
<tr>
<td class="nowrap" showactionitem="2">
<span class="group">
<span class="group__link"><a onclick="Check()" href="#">copy</a>
</span>
</span>
</td>
<td class="COLUMNNAME">AM-PAC</td>
<td class="COLUMNLONGNAME">AM-PAC Generic Outpatient Basic Mobility Short Form</td>
<td class="COLUMNNOTE"></td>
<td class="COLUMNRESTRICTEDYN">No</td>
<td class="COLUMNSPECIALTYID"></td>
<td class="COLUMNSEXFILTER">Both</td>
<td class="COLUMNAGEFILTERMIN">Any</td>
<td class="COLUMNTYPE">Score Only</td>
</tr>
<tr></tr>
<tr></tr>
</tbody></thead>
</table>
Likewise this table contains around 100 rows. I did the same using iteration and it is working fine.
Is it possible to find the parent of specific row without iteration?
You can use the parent method to find the parent of an element. Assuming that you have located a table cell, let's call it cell, you can get its row using parent and then the parent of the row with another call to parent:
cell.parent
#=> a <tr> element
cell.parent.parent
#=> the parent of the specific row - a <tbody> element in this case
Chaining multiple parent calls can become tedious and difficult to maintain. For example, you would have to call parent 4 times to get the table cell of the "copy" link. If you are after an ancestor (ie not immediate parent), you are better off using XPath:
cell.table(xpath: './ancestor::table')
#=> the <table> element containing the cell
browser.link(text: 'copy').tr(xpath: './ancestor::tr')
#=> the <tr> element containing a copy link
Hopefully Issue 451 will be implemented soon, which will remove the need for XPath. You would be able to call:
cell.parent(tag_name: 'table') # equivalent to `cell.table(xpath: './ancestor::table')`
There's no need for anything fancy, Watir has an Element#parent method.
You can use this one:
parent::node()
The below example will selects the parent node of the input tag of Id='email'.
Ex: //input[#id='email']/parent::*
the above can also be re-written as
//input[#id='email']/..
XPath tutorial for Selenium
I need to know if 1324 was Win or Loss in a table. How do I select the single <td> Element to know if it was a loss or a win.
<tr>
<td> 1323 </td>
<td> Won </td>
</tr>
<tr>
<td> 1324 </td>
<td> Loss </td>
</tr>
[...]
<tr>
<td> 1328 </td>
<td> Won </td>
</tr>
Whilst the answers are correct in this question, people are forgetting the context: Selenium. You give those XPath's to it, and it'll blow up in your face.
Selenium expects XPath queries to return physical DOM elements, and not attributes from those elements.
You should find the element, and use Selenium to get it's text. This could be .getText(), or .Text or something similar in whatever language you are using (C# and Java examples below - assuming driver is a valid Driver instance):
C#:
driver.FindElement(By.XPath("//td[text()="1324"]/following-sibling::td")).Text;
Java:
driver.findElement(By.xpath("//td[text()="1324"]/following-sibling::td")).getText();
Try this:
//td[text()='1324']/../td[2]/text()