Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium clicking on javascript link

Tags:

java

selenium

I'm having an issue with writing a Selenium test using Java and Spring.

I need Selenium to click on a delete button on a page that contains multiple delete buttons (a list of files). Using the Selenium IDE generates the following code

selenium.click("link=Delete");

which is basically useless. I haven't been able to figure out how to target the specific element contained in a table. Here's the source:

<tr onmouseover="mouseOver(this)" onmouseout="mouseOut(this)">
  <td class="thumbnail" align="center"><img src="/services/images/nav/resources.gif" /></td>
  <td colspan="3" onClick="nav('FileName'); return false">
    <a href="javascript:nav('FileName')">Basics</a></td>
 <td>
   <a class="actionButton" href="javascript:del('FileName')">Delete</a></td>
<td>&nbsp;</td>
</tr>   

I need to either a) find a way to return the xpath of the correct delete action or b) send the javascript command itself through the java code. I haven't been able to figure out how to to either, can anyone point me in the right direction?

like image 784
krazycat Avatar asked Jan 23 '26 05:01

krazycat


1 Answers

Is the "Filename" part unique?

If so, the appropriate XPath would be:

selenium.click("//a[@href=\"javascript:del('FileName')\"")

Also, did you click the first Delete link from Selenium IDE? If so, try clicking on one of the subsequent ones instead and see what it comes up with.

like image 111
Jonny Buchanan Avatar answered Jan 25 '26 19:01

Jonny Buchanan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!