[RC] How to click on a link which is under Table

1,539 views
Skip to first unread message

Mohammed Sikander

unread,
Mar 16, 2011, 3:06:30 AM3/16/11
to seleniu...@googlegroups.com
Hi,

I am not able to click on a link which is under a table. Clicking on this link, application is re-directing to another page. 

I tried with the followings:

selenium.click("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a");
selenium.click("//table[@id=('dgRedactionSet')]/descendant::tr[2]/descendant::td[4]/font/a");
selenium.click("css=table[@id=('dgRedactionSet')] tr:nth-child(2) td:nth-child(4) a");

but none of them are working.

Following is the HTML snippet

<table cellspacing="0" cellpadding="3" Border="0" border="0" id="dgRedactionSet" style="width:100%;border-collapse:collapse;">
<tr class="rowhead">
<td style="font-family:Verdana;font-size:10px;font-weight:bold;">Name</td><td style="font-family:verdana;font-size:10px;width:50%;">Remarks</td><td>Default</td><td style="font-family:Verdana;font-size:10px;">&nbsp;</td><td align="Right" style="font-family:Verdana;font-size:10px;">&nbsp;</td>
</tr><tr class="oline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl2_Label1">Catalyst</span>
</td><td style="font-family:verdana;font-size:10px;">&nbsp;</td><td>
<input id="dgRedactionSet__ctl2_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl2:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr>

Please let me know to solve this problem.

Thanks,
Sikander

Mark Collin

unread,
Mar 16, 2011, 4:56:52 AM3/16/11
to seleniu...@googlegroups.com

You’re not supposed to be able to click on links that a human user can not click.  What would this test prove?

 

Get the devs to expose the link properly, or write a script that performs the pre-requisites for exposing the link before trying to click on it.

--
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.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Mohammed Sikander

unread,
Mar 16, 2011, 5:21:41 AM3/16/11
to seleniu...@googlegroups.com
You’re not supposed to be able to click on links that a human user can not click
I am able to click on this link. Clicking on "Edit" link application is taking to new page.

write a script that performs the pre-requisites for exposing the link before trying to click on it.
I have verified with selenium.isElementPresent("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a") - no issues, the test got passed.

Only problem was when i try to click on it, giving error like element not found or invalid xpath....

Mark Collin

unread,
Mar 16, 2011, 7:55:23 AM3/16/11
to seleniu...@googlegroups.com

So you mean a link within the table, rather than under the table?

 

If I am now understanding you correctly try using this xpath:

 

//table[@id=’dgRedactionSet’]/descendant::tr[4]/td/a[.=’Edit’]

 

This will always click on the fourth row in the table which may be good, or may be bad.  I suspect you want to click on a row that has specific text in one of the cells, if you wanted to click on the edit link for the row that has the text Catalyst in the first cell you should instead use an xpath like this:

 

//table[@id=’dgRedactionSet’]/descendant::tr[td[1][.=’Catalyst’]]/td/a[.=’Edit’]

 

Regards

 

Mark

Mohammed Sikander

unread,
Mar 16, 2011, 8:31:44 AM3/16/11
to seleniu...@googlegroups.com
No, its not identifying.
Following all are working fine in IDE but not in RC

selenium.click("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a");
selenium.click("//table[@id=('dgRedactionSet')]/descendant::tr[2]/descendant::td[4]/font/a");
selenium.click("//table[@id=’dgRedactionSet’]/descendant::tr[4]/td/a[.=’Edit’]")

here is the complete table structure:
<table cellspacing="0" cellpadding="3" Border="0" border="0" id="dgRedactionSet" style="width:100%;border-collapse:collapse;">
<tr class="rowhead">
<td style="font-family:Verdana;font-size:10px;font-weight:bold;">Name</td><td style="font-family:verdana;font-size:10px;width:50%;">Remarks</td><td>Default</td><td style="font-family:Verdana;font-size:10px;">&nbsp;</td><td align="Right" style="font-family:Verdana;font-size:10px;">&nbsp;</td>
</tr>
<tr class="oline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl2_Label1">Catalyst</span>
</td><td style="font-family:verdana;font-size:10px;">&nbsp;</td><td>
<input id="dgRedactionSet__ctl2_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl2:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="eline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl3_Label1">Default</span>
</td><td style="font-family:verdana;font-size:10px;">Default Redaction Set</td><td>
<input id="dgRedactionSet__ctl3_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl3:chkIsDefault" checked="checked" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl3$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl3$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="oline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl4_Label1">Federal Case Redactions</span>
</td><td style="font-family:verdana;font-size:10px;">Redactions to produce in Federal Case</td><td>
<input id="dgRedactionSet__ctl4_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl4:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl4$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl4$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="eline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl5_Label1">FTC</span>
</td><td style="font-family:verdana;font-size:10px;">&nbsp;</td><td>
<input id="dgRedactionSet__ctl5_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl5:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl5$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl5$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="oline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl6_Label1">IED Review</span>
</td><td style="font-family:verdana;font-size:10px;">&nbsp;</td><td>
<input id="dgRedactionSet__ctl6_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl6:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl6$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl6$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="eline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl7_Label1">Redaction Demo CAP</span>
</td><td style="font-family:verdana;font-size:10px;">Redaction Demo CAP</td><td>
<input id="dgRedactionSet__ctl7_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl7:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl7$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl7$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr><tr class="oline">
<td style="font-family:Verdana;font-size:10px;">
<span id="dgRedactionSet__ctl8_Label1">Test</span>
</td><td style="font-family:verdana;font-size:10px;">&nbsp;</td><td>
<input id="dgRedactionSet__ctl8_chkIsDefault" type="checkbox" name="dgRedactionSet:_ctl8:chkIsDefault" onclick="HandleCheckBox(this)" />
</td><td align="Right" style="color:#3300FF;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl8$_ctl0','')" style="color:#3300FF;">Edit</a></td><td align="Right" style="color:Blue;font-family:Verdana;font-size:10px;"><a href="javascript:__doPostBack('dgRedactionSet$_ctl8$_ctl1','')" style="color:Blue;">Delete</a></td>
</tr>
</table>

Thanks,
Sikander


Mark Collin

unread,
Mar 16, 2011, 10:19:02 AM3/16/11
to seleniu...@googlegroups.com

If it works in IDE it proves that the xpath is correct, are you sure you are seeing the same markup in the RC window?

Joel Weierman

unread,
Mar 16, 2011, 4:33:22 AM3/16/11
to Selenium Users
At the risk of being pedantic, which link are you trying to click on?
I assumed you already tried the following?

"link=Edit"

-Joel

On Mar 16, 12:06 am, Mohammed Sikander <sikander.qure...@gmail.com>
wrote:

Mohammed Sikander

unread,
Mar 17, 2011, 12:21:41 AM3/17/11
to seleniu...@googlegroups.com
But, "link=Edit" will clicks only for the first "Edit" link, i want to click each "Edit" link and do assertion.

Leonardo Galani

unread,
Mar 17, 2011, 12:40:56 AM3/17/11
to seleniu...@googlegroups.com
I never saw a xpath with this '

Are you sure that path is corret? did you got it from selenium or xpather.. ? did u tried webdriver findelementbyxpath to see what happend?
Att
Leonardo Barba Galani
Arquiteto de Teste
Java, Selenium e Coca Cola
> name="dgRedactionSet:_ctl2:chkIsDefault" X_onclick="HandleCheckBox(this)" />

> </td><td align="Right"
> style="color:#3300FF;font-family:Verdana;font-size:10px;"><a
> href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl0','')"
> style="color:#3300FF;">Edit</a></td><td align="Right"
> style="color:Blue;font-family:Verdana;font-size:10px;"><a
> href="javascript:__doPostBack('dgRedactionSet$_ctl2$_ctl1','')"
> style="color:Blue;">Delete</a></td>
> </tr>
>
> Please let me know to solve this problem.
>
> Thanks,
> Sikander

--
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.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Mohammed Sikander

unread,
Mar 18, 2011, 1:05:16 AM3/18/11
to seleniu...@googlegroups.com
I inspected the element with Xpather.It just works fine in IDE. Even in RC if i say 
selenium.isElementPresent("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a"); - the element is identifying and the test pass.

When i click on the same element i.e.,
selenium.isElementPresent("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a"); it is giving following error

com.thoughtworks.selenium.SeleniumException: ERROR: Element //table[@id=('dgRedactionSet')]/tbody/tr[2]/td[2]/font/a not found

Anybody got success clicking on a link which is under table? Please let me know the solution for this.

Thanks,
Sikander

Mohammed Sikander

unread,
Mar 18, 2011, 2:28:42 AM3/18/11
to seleniu...@googlegroups.com
Just corrected....

On 18 March 2011 10:35, Mohammed Sikander <sikander...@gmail.com> wrote:
I inspected the element with Xpather.It just works fine in IDE. Even in RC if i say 
selenium.isElementPresent("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a"); - the element is identifying and the test pass.

When i click on the same element i.e.,
selenium.click("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a"); it is giving following error

Mark Collin

unread,
Mar 18, 2011, 4:34:23 AM3/18/11
to seleniu...@googlegroups.com

Where does the test fail if you do:

 

assertTrue(selenium.isElementPresent("//table[@id=('dgRedactionSet')]/tbody/tr[2]/td[4]/font/a"));

 

I suspect the element is not there but because you are not checking the result returned by isElementPresent you are not realising that it is returning false.

 

Regards

 

Mark

Mohammed Sikander

unread,
Mar 18, 2011, 4:43:38 AM3/18/11
to seleniu...@googlegroups.com
Yes, its failing to identify the element now. Before i haven't included "AssertTrue"

but, what should be the correct Xpath or CSS to click on "Edit" button?

Thanks,
Sikander

Mark Collin

unread,
Mar 18, 2011, 4:56:20 AM3/18/11
to seleniu...@googlegroups.com

I’ll refer you back to my previous mail which gave you the following XPath:

 

//table[@id=’dgRedactionSet’]/descendant::tr[td[1][.=’Catalyst’]]/td/a[.=’Edit’]

 

If this doesn’t work the HTML is not as previously specified, or you are loading the page you think you are loading.

Mohammed Sikander

unread,
Mar 18, 2011, 7:33:59 AM3/18/11
to seleniu...@googlegroups.com
No, its not identifying..

But i found the alternative for this, but this was not i am looking for...
assertTrue(selenium.isElementPresent("//a[contains(@href,'ctl2$_ctl0')]"));

Mark Collin

unread,
Mar 18, 2011, 7:42:41 AM3/18/11
to seleniu...@googlegroups.com

That is scanning through every anchor element in the page and checking where the anchor links to.  If you have multiple anchors that link to the same place this will result in selenium just grabbing the first one it finds no matter where it is (so it may not pick up one in a table never mind one in the row you are specifically looking for). 

 

If you are trying to check that a specific link exists in a specific place this is not a good thing to do.  Also the query is bad from a performance point of view as it will scan the entire DOM every time rather than scanning a section of the DOM.  If you are running tests in a browser with a bad JavaScript implementation (I’m looking at you IE6) you will notice the tests are taking much longer by using an xpath like this.

 

Do you have a link to the live site that is publically accessible?

Mohammed Sikander

unread,
Mar 18, 2011, 8:40:46 AM3/18/11
to seleniu...@googlegroups.com
No, it is not publicly available site.

Right now i am moving forward with this solution. Need to investigate more on this. 

Are you/anybody able to successfully click on a link which is inside the table?

Please let me know...

Mark Collin

unread,
Mar 18, 2011, 9:47:02 AM3/18/11
to seleniu...@googlegroups.com
Yup, do it all the time with XPaths like the one I supplied to you.

One other option is run a W3C validation on the page you are testing and see
if it throws up any errors relating to unclosed elements. If you have an
unclosed element hiding away in there somewhere it could be breaking the DOM
which would cause the XPath to fail even though it should work from the
snippet of HTML that we have seen.

Please let me know...

> *From:* seleniu...@googlegroups.com [mailto:
> seleniu...@googlegroups.com] *On Behalf Of *Mohammed Sikander
> *Sent:* 18 March 2011 11:34
>
> *To:* seleniu...@googlegroups.com
> *Subject:* Re: Re: [selenium-users] Re: How to click on a link which

> is under Table
>
>
>
> No, its not identifying..
>
>
>

> But i found the alternative for this, but this was not i am looking for..=

Piotr K

unread,
Mar 18, 2011, 10:00:15 AM3/18/11
to Selenium Users
Hi Mohammed,

I have the same problem. Do you have some solution already?

Please let me know...

On 18 Mar, 14:47, "Mark Collin" <m...@ardescosolutions.com> wrote:
> Yup, do it all the time with XPaths like the one I supplied to you.
>
> One other option is run a W3C validation on the page you are testing and see
> if it throws up any errors relating to unclosed elements.  If you have an
> unclosed element hiding away in there somewhere it could be breaking the DOM
> which would cause the XPath to fail even though it should work from the
> snippet of HTML that we have seen.
>
> -----Original Message-----
> From: seleniu...@googlegroups.com
>
> [mailto:seleniu...@googlegroups.com] On Behalf Of Mohammed Sikander
> Sent: 18 March 2011 12:41
> To: seleniu...@googlegroups.com
> Subject: Re: Re: [selenium-users] Re: How to click on a link which is under
> Table
>
> No, it is not publicly available site.
>
> Right now i am moving forward with this solution. Need to investigate more
> on this.
>
> Are you/anybody able to successfully click on a link which is inside the
> table?
>
> Please let me know...
>
> On 18 March 2011 17:12, Mark Collin <m...@ardescosolutions.com> wrote:
>
> > That is scanning through every anchor element in the page and checking
> > where the anchor links to.  If you have multiple anchors that link to
> > the same place this will result in selenium just grabbing the first
> > one it finds no matter where it is (so it may not pick up one in a
> > table never mind one in the row you are specifically looking for).
>
> > If you are trying to check that a specific link exists in a specific
> > place this is not a good thing to do.  Also the query is bad from a
> > performance point of view as it will scan the entire DOM every time
> > rather than scanning a section of the DOM.  If you are running tests
> > in a browser with a bad JavaScript implementation (I'm looking at you
> > IE6) you will notice the tests are taking much longer by using an xpath
> like this.
>
> > Do you have a link to the live site that is publically accessible?
>
> > *From:* seleniu...@googlegroups.com [mailto:
> > seleniu...@googlegroups.com] *On Behalf Of *Mohammed Sikander
> > *Sent:* 18 March 2011 11:34
>
> > *To:* seleniu...@googlegroups.com
> > *Subject:* Re: Re: [selenium-users] Re: How to click on a link which
> > is under Table
>
> > No, its not identifying..
>
> > But i found the alternative for this, but this was not i am looking for..=
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com
>
>

Michael Yang

unread,
Mar 18, 2011, 11:16:09 AM3/18/11
to seleniu...@googlegroups.com, Mohammed Sikander
I have no problem clicking on the links in each row in the table.

Try the xpath like this:
selenium.click("//td/span[text()='Default']/following::a[text()='Edit']");

It means the 'Edit' link in the row that begins with the 'Default' text.
For the other rows, just replace the 'Default' to the Name value in that row.

== Life is a Project ==
Reply all
Reply to author
Forward
0 new messages