Im currently testing using PHPUnit and i need to create and delete the same things. So i create something called test, i want to be able to find it and delete it. I have multiple Delete buttons on the page, and it works by doing something like this -
$this->click("xpath=(//img[@title='Delete'])[11]");
but by choosing [11] for example, it is only using the delete button from row 11. And if Test isnt Row 11 for example, i will delete something i do not wish to delete.
I wish to try and delete a specific row by finding a row with a certain id attached to it.
The row may have the words "Test" followed by more information within columns. Then a delete button at the end titled 'Delete'. I wish to find the row with the id or words 'Test' and then find and use the 'Delete' title on that row.
Any help?
EDIT -Example image of a row. I would like to grab the first text, and then use the very last button on the right titled 'Delete'
http://i.stack.imgur.com/S4BNE.png
SECOND EDIT - This is the whole table, it contains all of the rows and within the rows it contains the td's (Obviously, as you'd know). This is where ill find the text im trying to find. This tr would count as the 4th of 6.
This shows the td containing delete, a td containing 'Test Profile' and the whole table itself. http://i.imgur.com/4r1tsJe.png
TL;DR Essentially, im trying to do, Where td contains 'Test', use 'Delete' from the same row.
Not very clear but I'll try to guess from your comments.
Forget about rows, but let's find all the td
with "Test" (or some text you want in it)
descendant::td[contains(.,'Test')]/
and from here select the following-sibling td
that contains a delete image
following-sibling::td//img[@title='Delete']
now you have the set of images nodes to click on, for each row.
Of course, if your function
$this->click("xpath=.....");
accepts only one node at the time, one possibility is to put the parenthesis and select always the first node (assuming that your test will delete it)
(descendant::td[contains(.,'Test')]/following-sibling::td//img[@title='Delete'])[1]
Even if the node is deleted when you click on it, in the next test this expression will always match, until there is any node left on the page
This is similar (not perfectly the same) to having a for loop ?
buttons = "xpath=....."
for each b in buttons do {
$this->click(b);
}
hope it helps
If you want to find the first row that contains Test in the first <td>
element, or that has an id attribute of "Test" on the <tr>
element; and you want to click the Delete img element from that row, you could try
$this->click("xpath=(//tr[@id='Test' or contains(td[1], 'Test')]//img[@title='Delete'])[1]");
But this is somewhat guesswork, since I can't see the HTML you're working with.
Since it looks like 'Test' could be in all-caps or in mixed-case, you may have to build in some case-insensitivity:
$this->click("xpath=(//tr[@id='Test' or
contains(translate(td[1], 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'TEST')]//img[@title='Delete'])[1]");
Yes it's kludgy, but AFAIK PHP only supports XPath 1.0.