xpath - how to find a delete link in a given table row? - selenium

Given the HTML below how can I find the delete link?
I've been able to select the row with:
//td[contains(text(),'DeleteMe')]/../../tr
but I can't seem to find a way to select the delete button.
For example I tried:
//td[contains(text(),'DeleteMe')]/../../tr//a[#class='delete_link'] but it did not select the link.
I can't use the ID's 403, 113, 112, etc and I need a script without actual ID's for re-testing purposes.
<tr class="odd" id="activity_403">
<td class="name">DeleteMe</td>
<td class="direct">false</td>
<td class="">
<ul>
<li>Language Therapist</li>
<li>Speech Therapist</li>
</ul>
</td>
<td class="">
View
Edit
Delete
</td>
</tr>

Found it:
//td[contains(text(),'DeleteMe')]/../../tr//a[contains(#class,'delete_link')]

Related

How to create conditional xpath in selenium?

My HTML code looks like:
Table 1: And Table 2
<table id="ContentPlaceHolder_Body0">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
<table id="ContentPlaceHolder_Body1">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
When I use //*[contains(text(),'Some Name')] this xpath selects 2 values while I need to select only one value by Text.
I need to use that xpath with Text.
I'm trying to create xpath to get the "Some Name" from Table 2, element locator by using Text.
So I created this Xpath:
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
This xpath is not working, need help to create correct xpath.
Given your HTML, this XPath works for me
//table[#id='ContentPlaceHolder_Body1']//td[text()='Some Name']
I think the issue with your XPath is that you were using #text() when it should be text().
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
^ remove the #
You need to just remove the #
//table[#id='ContentPlaceHolder_Body1']//tr//td[text()='Some Name']

Populating table with object containing an array in vuejs?

I am trying to populate table with an object which contains an array. I am able to successfully do that but I want each task name to have its own row right now they are coming in a single row.
{level_image :"image"level_name:"1"task_name: ["game","taskgame","jenga"]}
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td v-for="task in tel.task_name">{{task}}</td>
</tr>
You're missing the obvious: if you want each one to have its own row, you need to put the v-for in a <tr> tag (like you did for result). Exactly how you deal with the <td>s is up in the air, but it might go like this:
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<tr v-for="task in tel.task_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td>{{task}}</td>
</tr>
</tr>
Or if you mean you want each one to be on a separate line within a table cell, it could be
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td><div v-for="task in tel.task_name">{{task}}</div></td>
</tr>
The main idea is that you want the v-for to be associated with the type of tag that creates the entity you want each task in.

PHPUnit, Selenium - Click on link in row based on the value of another column in the same row

I think it's a stupid question, but I cant find an answer. I have table with many columns (name, date, link, etc.). I want to click on link based on the "name" value.
Here is short example:
<tr>
<td>
name value
</td>
<td>
date
</td>
<td>
<a href="">
link
</a>
</td>
</tr>
<tr>
the same format with different values
</tr>
Thanks for answers
This xpath will work for you, I think:
//td[contains(text(), 'name value')]/../td/a
It will find the <td> that contains 'name value', go back up to the containing <tr>, then back down to the <td> that has a<a> as a child in the same <tr>.
If I understand phpunit correctly, the command will look something like this:
$this->click("xpath=//td[contains(text(), 'name value')]/../td/a");

How to add cells in a column in html

is there a way to add cells in a row column in html table without adding another table inside the row column
I have attached the image. and here is my code
<tr>
<tbody>
<td>Name</td>
<td><div id="span1">Units</div>
<div id="span2" class="side-border">price</div>
<div id="span2" class="r">value</div>
</td>
</tbody>
</tr>
If you want to have some different structure of your rows, you should check colspan and rowspan. The numbers should add up.
Example
<table border="1px">
<tr>
<td colspan="5">Hello</td>
<td>World</td>
</tr>
<tr>
<td rowspan="2">col 1</td>
<td colspan="4">CENTER</td>
<td>right</td>
</tr>
<tr>
<td colspan="3">Text</td>
<td colspan="3">bottom right</td>
</tr>
</table>
If you were to add the numbers from colspan they add to 6 and rowspan goes to 3. There are some things you have to take care of though. It's a little hard for me to explain now what those are, just try to visualise how you want your table to look, and then follow this:
The table should have the max number of rows
The table should have the max number of columns
rowspan used across table has to add up (more or less)
colspan used across table has to add up (more or less).
Follow that, and after writing the HTML for a few "complex" tables, you'll get the gist of it.

XPath Text Search/Sibling Selection

This question might be a little specific but the test program im writing uses XPath to find the data i need in HTML. This piece of HTML(found here) is what im trying to parse.
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="textSm" align="right">1. </td> <!-- Location of the number is here -->
<td align="left" nowrap>
P Sandoval <!-- Player location is here of the number is here -->
</td>
</tr>
</table>
My goal is to find the name of the person by using the number that corresponds to him to find him. This requires me to find a node by the specific text contained in "td class="textSm" align="right">1. </td>" and then find the sibling of that node "<td align="left" nowrap>" then find the child of that sibling "P Sandoval" to get the desired result. I was wondering what kind of query I could use to find this. Any help is very much appreciated.
Use:
table/tr/td[starts-with(., '1.')]/following-sibling::td/a
This assumes that the context (current node) against which the XPath expression above is evaluated, is the parent of table.
//tr[td = "1"]/td[2]/a
For all TRs which have a TD equal to '1', give from the second child TD the A element.