Deleting rows created at runtime

1,028 views
Skip to first unread message

newbie

unread,
Jul 13, 2012, 1:13:57 AM7/13/12
to seleniu...@googlegroups.com
I am trying to add few rows in a web based application UI and then delete the same row using Selenium IDE. Now the problem is the web page could have 0 or more number of rows already present. I was using xpath to determine the position of the element like 

xpath=(//a[contains(text(),'Delete')])[4]

But in case the row I added is not the fourth row, any other fourth row will get deleted. Also, the rows I add has 3-4 columns and there could be identical column data present in the existing rows.

for example

Agent 1      UK         Blue
Agent 2     France    Yellow
Agent 3     UK          Yellow
Agent 2     Italy        White
Agent 5    Italy         Blue


Any help?


newbie

unread,
Jul 13, 2012, 6:02:39 AM7/13/12
to seleniu...@googlegroups.com
I got the number of rows in the UI and stored in a variable row by using 
<td>storeXpathCount</td>
<td>//html/body/div[2]/center/table/tbody/tr</td>
<td>row</td>

but how do i use the variable row in the xpath to delete the nth row

what i need to do is use something like

xpath=(//a[contains(text(),'Delete')])[row] 

instead of 
xpath=(//a[contains(text(),'Delete')])[4]    - to delete the 3rd row in the table

as the number of rows will be dynamic


here [row] or [${row}] doesn't work
Message has been deleted

newbie

unread,
Jul 16, 2012, 1:28:54 AM7/16/12
to seleniu...@googlegroups.com
There is a delete link for each row. And the problem is I cannot detect the row by any of the values present as there could be other rows present with the same value in any particular column.


On Saturday, July 14, 2012 9:19:34 PM UTC+5:30, Veeraraghavan Ramamoorthy wrote:
Is there any possibility of selecting the row and deleting the row by clicking on "delete" button.

Regards
Veera.

Karthik Kulkarni

unread,
Jul 16, 2012, 3:09:51 AM7/16/12
to seleniu...@googlegroups.com
how abt the x path of the delete link on each row . There shd be some change with that

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/HSkRzr7InUQJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

Selenium User

unread,
Jul 16, 2012, 4:42:34 AM7/16/12
to seleniu...@googlegroups.com
Hi, 

Try identifying text of the each row and check whether it is added by you or not. 
If yes, delete that row from the table. 

Thanks

Selenium User. 

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Darrell Grainger

unread,
Jul 16, 2012, 1:38:51 PM7/16/12
to seleniu...@googlegroups.com
How would you find the row you wanted to delete as a manual tester? What is it that you see which says, this is the row I want to delete? For example, if I added the fourth row and it is the set { "Agent 2", "Italy", "White" }, the 'Delete' link is on the same row and I can find the table  then I might do:

    WebElement table = driver.findElement(by1);  // by1 is a By locator which finds the table
    String xpath1 = "tbody/tr/td[text()='Agent 2']/../td[text()='Italy']/../td[text()='White']/../a[text()='Delete']";

This xpath will basically find the row which has all three strings on it. I'm using exact match for everything but you can change that to contains(text(),'Agent 2'), etc. if that matters. If having all three strings on the same row isn't enough and the order matters, i.e. you might have one row with { "Agent 2", "Italy", "White" } and another with { "White", "Agent 2", "Italy" } then you change the above xpath by adding position() indicates, e.g.

    String xpath1 = "tbody/tr/td[text()='Agent 2' and position() = 1]/../td[text()='Italy' and position() = 2]/../td[text()='White' and position() = 3]/../a[text()='Delete']";

Darrell

Vladislav Mkrtychev

unread,
Jul 16, 2012, 3:30:36 PM7/16/12
to seleniu...@googlegroups.com
Hello,

Could you post HTML for the delete link?
And for one of the rows in that table.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/TUbSaCCYcH0J.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.



--
Vladislav Mkrtychev

santoshsarma jayanthi

unread,
Jul 17, 2012, 1:36:26 AM7/17/12
to seleniu...@googlegroups.com
As Darrell said, You need to locate the delete link based on the unique value(column) in that row using XPath.

If you post your html snippet here,I/Anyone shall try to give xpath.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Regards,
-SantoshSarma
LinkedIn | Twitter | Facebook

Sweta Shahi

unread,
Jul 17, 2012, 8:14:33 AM7/17/12
to seleniu...@googlegroups.com
Thanks Darrell,

But I am using IDE not sure how I can execute your commands in IDE. The copied xpath of each of the element of the row I added are as follows:

Agent 1 = /html/body/div[2]/center/table/tbody/tr[7]/td

White = /html/body/div[2]/center/table/tbody/tr[7]/td[2]

Italy = /html/body/div[2]/center/table/tbody/tr[7]/td[3]

that is the row I added was the seventh row in the table. The locator isn't able to find the element if i give something like 

xpath=//html/body/div[2]/center/table/tbody/tr[contains(text(),'Agent 1')]

Here is the html snippet for that row:

<tr>
<td style="text-align: left;">Agent 1</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Italy</td>
<td style="text-align: left;"></td>
<td>
<a href="javascript:editAgent('updatepteagent.htm?id=23')">Edit</a>
</td>
<td>
<a href="javascript:deleteAgent('deleteagent.htm?id=23')">Delete</a>
</td>
</tr>




newbie

unread,
Jul 19, 2012, 6:15:53 AM7/19/12
to seleniu...@googlegroups.com
Any help? I am still stuck!

santoshsarma jayanthi

unread,
Jul 19, 2012, 6:56:52 AM7/19/12
to seleniu...@googlegroups.com
try this
//td[text()='Italy']/following-sibling::td/a[text()='Delete']

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/kpjG_L-9COsJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

ready123

unread,
Aug 7, 2012, 9:12:16 AM8/7/12
to seleniu...@googlegroups.com
Hey 


Did you get reply for your proble....i am also facing same problem kindly reply me

newbie

unread,
Aug 7, 2012, 9:27:12 AM8/7/12
to seleniu...@googlegroups.com
No I didn't get a response here. I am hence deleting the last row using 

xpath=(//a[contains(text(),'Delete')])[last()] 

this works for screens where the most recent row is added at the bottom of the table

but i m still working for a better solution where I scan through all the values using a while loop and then select the row based on the values I had entered while creating the row. something like 

while (i < numrows)
if firstcolumn_value = "my test value" goto outofloop
i++
endwhile
outofloop
clickAndWait | xpath=(//a[contains(text(),'Delete')])[${i}] 


hope this helps.
Reply all
Reply to author
Forward
0 new messages