Do Edit or Delete Action in table With Dynamic ID

151 views
Skip to first unread message

Shin Yue

unread,
Apr 17, 2014, 4:34:49 AM4/17/14
to seleniu...@googlegroups.com
Hello, I encountered some problem to identify dynamic ID in table that have dynamic IDs to do some action like edit or delete, because the IDs is dynamic shown, I don't understand how to do action like edit data from code no 12345 when shown id is id=...0.
How to solving this? I'm using Selenium IDE. How we can 
do edit or delete when the number id is dynamic?
Here is the HTML code

<div>
    <table id="gvSomething" class="mGrid" cellspacing="0" style="border-collapse:collapse;">
       
<tbody>
       
<tr>
           
<th scope="col">
               
<a id="CODE">code no.</a>
           
<th scope="col">
               
<a id="NAME">name</a>
           
<th scope="col">
               
<a id="STATUS">active</a>
           
<th scope="col"> CONTROL </th>
       
</tr>    
       
       
<tr>
           
<td align="center">
               
<span id="Code_0">12345</span>
           
</td>
           
<td>
               
<span id="Name_0">zero</span>
           
</td>
           
<td valign="middle" align="center">
               
<span id="Status_0">Yes</span>
           
</td>
           
<td valign="middle" align="center">
               
<input id="Edit_0" type="image" src="../Images/Edit.gif" title="Edit Record" name="Status$ctl02$imbEdit">
               
<input id="Delete_0" type="image" src="../Images/Delete.gif" title="Delete Record" name="Delete$ctl02$imbDelete">
           
</td>
       
</tr>
       
       
<tr>
           
<td align="center">
               
<span id="Code_1">098765</span>
           
</td>
           
<td>
               
<span id="Name_1">one</span>
           
</td>
           
<td valign="middle" align="center">
               
<span id="Status_1">Yes</span>
           
</td>
           
<td valign="middle" align="center">
               
<input id="Edit_1" type="image" src="../Images/Edit.gif" title="Edit Record" name="Status$ctl03$imbEdit">
               
<input id="Delete_1" type="image" src="../Images/Delete.gif" title="Delete Record" name="Delete$ctl03$imbDelete">
           
</td>
       
</tr>
       
</tbody>
   
</table>
</div>


DongXiang

unread,
Apr 20, 2014, 8:55:17 AM4/20/14
to seleniu...@googlegroups.com
Hi,
Find the tr which has the expect Code.no, then, find edit or delete img in the tr.
XPATH can help you a lot.


Date: Thu, 17 Apr 2014 01:34:49 -0700
From: c22...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Do Edit or Delete Action in table With Dynamic ID
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6bb42cac-61b8-49d4-95e8-39aaa19df62d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shin Yue

unread,
Apr 20, 2014, 10:27:59 PM4/20/14
to seleniu...@googlegroups.com
Hi David, thx for replying.
How to use Xpath to find that? Sorry for asking too much, because I'm new user using Selenium

Nitin Lomte

unread,
Apr 18, 2014, 1:45:08 PM4/18/14
to seleniu...@googlegroups.com

Hi,
You can use xpath to reach each element and then use getattribute (id) to that element so that now you have id value , now in if you can chek wether last charter is 0 or 1 and do the secifix axtion.

Regards,
Nitin Lomte.

Shin Yue

unread,
Apr 21, 2014, 2:46:45 AM4/21/14
to seleniu...@googlegroups.com
Hi Nitin, thx for replying. I've some question :
 
Does xpath from my HTML code seems like this?
//*[@id="gvBOD_imbEdit_0"]
//*[@id="gvBOD_imbDelete_0"]

How to using getattribute? I've tried typing in command, but it didn't show. For getattribute ID, which ID should I use? The image of edit or delete?

Nitin Lomte

unread,
Apr 21, 2014, 3:08:52 AM4/21/14
to seleniu...@googlegroups.com

use this xpath, use loop to iterate through it.

ele_object=//table[@id='gvSomething']/tbody/tr[2]/td/span

ele_object=get_attribute('id')

get_attribute() is python  syntax search for java syntax



DongXiang

unread,
Apr 21, 2014, 3:09:09 AM4/21/14
to seleniu...@googlegroups.com
HI

Using following to find the tr

WebElement tr = webDriver.findElement(By.xpath("//tr[text()='expect tr']"));

Then using the tr to find the edit or delete img by following xpath

WebElement editImg = tr.findElement(By.xpath("descendant::input[contains(@src,'Edit.gif')]"));

Best Regards,
--david


Date: Sun, 20 Apr 2014 19:27:59 -0700
From: c22...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Do Edit or Delete Action in table With Dynamic ID

Shin Yue

unread,
Apr 21, 2014, 3:46:11 AM4/21/14
to seleniu...@googlegroups.com
Hi, Nitin. I think I understand how does that code works, but how should I put that code in IDE?
Thx

Shin Yue

unread,
Apr 21, 2014, 3:46:44 AM4/21/14
to seleniu...@googlegroups.com
Hi David, about 'expect tr' does it mean which row that I want to do the action right?
How can I put this code in IDE?
Thx

DongXiang

unread,
Apr 21, 2014, 5:23:48 AM4/21/14
to seleniu...@googlegroups.com
yes, expect means the tr which you want to do the action on, I am not familiar with IDE, you can expect the IDE record to Java or others, I am not sure, but sounds you can. you can do the change after the exporting,

Best Regards,
--david


Date: Mon, 21 Apr 2014 00:46:44 -0700
Reply all
Reply to author
Forward
0 new messages