Monkomatic has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I posted this previously but was told it was alittle to complicated. So i am trying to ask the question in as few words as possible.

I am trying to click on a link/image with no name value or ID.

The full html source code is quite huge.. quite huge... or i would post it. I am using selenium 1 to make the requets

The code is warped. Dont ask me how. dont know. when you look at the source it contains both the previous page and the add card page so it makes tracing the dom difficult....

Page Snippet is:

<td colspan="2" class="add-instrument-container"> <input title="" alt="add your card" class="payselectButtonsSprite s_ad +d-your-card add-instrument-button action_link" id="" value="" name="" + src="https://images.com/images/G/01/x-locale/common/transparent-pixe +l._V192234675_.gif" ref="ox_pay_page_cc_add" type="image" border="0"> + <img class="loading-small" src="https://images.com/im +ages/G/01/x-locale/common/loading/loading-small._V192239831_.gif" alt +=""> </td> </tr>

I do realize it is an xpath solution. However all the attempts i have tried have been from the web and selenium has many more flavors than perl so i was never sure my syntax was correct.

I am hoping somone knows the correct perl syntax for finding and clicking an image by alt or partial or full image name? Everytime i try to use @ i get an error and if i dont use it it complains the element cannot be found.

#$sel->click("xpath=//imgcontains($addcardlink)");

#$sel->click("xpath=//input@src=$addcardlink");

P.s. in the code : payselectButtonsSprite s_add-your-card add-instrument-button action_link I have been told add-your-card is a node. is there any perl selenium command to click the node element?

  • Comment on Clicking a link with perl with no VALUE, ID or NAME in perl Selenium 1
  • Download Code

Replies are listed 'Best First'.
Re: Clicking a link with perl with no VALUE, ID or NAME in perl Selenium 1
by Corion (Patriarch) on Oct 18, 2011 at 16:28 UTC
    #$sel->click("xpath=//imgcontains($addcardlink)"); #$sel->click("xpath=//input@src=$addcardlink");

    Neither of these two string expressions would be a valid XPath expression. And you conveniently also hide the value of $addcardlink from us. I get the feeling that you are not doing any work of your own and expect us to do your work for you, as your question has nothing to do with Perl and everything to do with learning XPath.

    I recommend using a browser plugin like XPather or Firebug. These plugins will show you a valid XPath expression to reach your element.

    Consider slowly refining your XPath expressions. First, start with an XPath expression that finds all a links. Then refine that expression to find all a links that contain an img image element. Next, refine the expression more, to match only links with an image whose src element contains() a certain string.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Clicking a link with perl with no VALUE, ID or NAME in perl Selenium 1
by anneli (Pilgrim) on Oct 19, 2011 at 01:36 UTC