Clicking link embedded in table row, by clicking on table row

1,632 views
Skip to first unread message

Thomas Jespersen

unread,
Aug 9, 2013, 6:26:41 AM8/9/13
to seleniu...@googlegroups.com
Hello everyone,

Recently with newer versions of Selenium a mechanism we used for clicking on certain links in our webapp has stopped working, and we're not sure whether this is expected to work, or if we need to do something else. Let me try to explain: We have links embedded in tables like so:

<table>
<tr id="rowid">
<td><a href="somepage"><span>link text</span></td>
</tr>
</table>

in which the styling is set up so the span tag fills out the td (and the a tag as well). In our tests we'd like to click on these links somehow, and until now we've been able to use

driver.findElement(By.id("rowid")).click();

which has been working without problems (the inner link would be clicked and the we'd be navigated to somepage). Until now, that is. Newer versions of Selenium and/or browsers fail to click on the link (from the looks of it, the driver does find table row, but clicking on it does nothing).

MY QUESTION is, in short, is it correct, as observed in FF, that these links are not clicked (and should we use another mechanism)? Or is it expected to work, and for reason it's stopped working? I've found a number of issues that ask very similar questions, but so far I haven't been able to find a definite answer (which closely enough matches our setup), so I thought I'd post a question here. I tried the #selenium channel, but haven't had any reply:
I've attached a minimal demonstration class, which should be able to work (almost) out of the box. In order to run it, correct the paths to firefox versions, chrome driver and the test HTML file.

Versions overview:
  • OS: Ubuntu 12.04 (LTS)
  • Firefox: 20, 22 and 23
  • Chrome: 28 (I haven't figured out multiple versions of Chrome on the same machine yet)
  • Chrome driver: 2.0 and 2.2
  • Selenium: 2.33 and 2.34

Any information/help is appreciated - thanks in advance!

LinkInTR.java
test1.html

Jorge

unread,
Aug 13, 2013, 5:30:56 PM8/13/13
to seleniu...@googlegroups.com
Just my 2 cents although I haven't tried it using Selenium so none of this may apply after all, but I did in the Firebug and Chrome console using JavaScript:

Unless something has changed in the past few versions, I had the understanding that when Firefox/ChromeDriver clicks, it finds as close as it can the middle of the element and clicks there. So I too am a little confused why it wouldn't work since, technically, you only have one TD element in your row which contains a link, your TR element is filled with that link, and it can even be interacted as such by clicking on any part of it and being taken to the designated web page.

However, in JavaScript "document.getElementById("row-id").click();" does not work in either Firebug or the Chrome console. Although this does work: "document.querySelector("#row-id>td>a").click();". I can only imagine maybe Selenium updated their clicking methodology to work the same way JavaScript would, but other than that I have no idea.

I'm sure you've thought of this, but I think it's worth mentioning: while clicking on the row may have worked in the past, it may be for the best that it doesn't work as such anymore since if someone were to do the same thing, but instead of only one column there were two, I believe it wouldn't work, at least according to how I understand clicking working in Firefox/Chromedriver. I think it's better to be more specific in this case because technically you're not clicking the row, you're clicking the link that resides in the row, so you're click on the link, not the row. 

I'm interested in a more detailed or correct response myself, but in the meantime, since you may have to change it anyway, you should look into using a different locator method that will work. 
Reply all
Reply to author
Forward
0 new messages