tags:

views:

45

answers:

1

I am new to Selenium and coding. What I am trying to do is click a dynamic link. Here is the scenario.

I have to find a dynamic link in a div that has multiple links.

The link I want to click has the myimage attribute and the link will always be different. There can be N-links in the div and some of the links won't have the myimage attribute.

I can locate the div using XPath, but I am having trouble finding the link I want in the div

In short, I want to look through the list of dynamic links in a div, find a link that has the myimage class and click it.

Can someone suggest a reference or provide a code snippet on how to do this with Selenium using C#?

A: 

I'm assuming that you have the latest version of selenium.

All you need is to extend the XPath you have for the div to include the link with the attribute. I haven't tried this in code but should work:

Selenium.Click("xpath=//a[@class='myimage']")

Check this article for more details

Nathan
Thanks for pointing me in the right direction. Here's what actually worked since the link and image are siblings in a parent node. selenium.Click("xpath=//img[@class='myimage']/../a");
Can I ask if my answer was of help could you mark it as the answer. Cheers.
Nathan