Selenium clicking javascript link

I am having trouble writing a Selenium test using Java and Spring.

I need Selenium to click the delete button on a page containing several delete buttons (file list). Using Selenium IDE generates the following code

selenium.click ("link = delete");

which is basically useless. I was not able to figure out how to configure the target element contained in the 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 xpath to the correct delete action, or b) send the javascript command directly through java code. I could not understand how to what, can someone point me in the right direction?

+3
source share
4 answers

" "?

, XPath :

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

, Selenium IDE? , , .

+3

firefox XPath Checker. html firefox, XPath , . , XPath, Selenium.

0

xpath , :

  • FireBug (Firefox addon): HTML firebug, Xpath .
  • Xpath (Firefox addon): , , xpath
0

I partially relate to using CSS for Selenium ids for two reasons -

  • readability
  • Browser Independence (XPath recognition slower in IE)

The limitation is that several elements with the same name must have a distinguishable attribute.

In your source, a Selenium CSS identifier command will read:

selenium.click("css=a.actionButton[href=javascript:del('FileName')]");

if indeed the href attribute provides a distinction between other Delete buttons

0
source

Source: https://habr.com/ru/post/1787724/


All Articles