20

I need to click on the below href element,which is present among similar href elements.

<a id="oldcontent" href="listDetails.do?camp=1865"><u>Re-Call</u></a>

Can anyone provide me xpath to click the above href link?

starball
  • 20,030
  • 7
  • 43
  • 238
cxyz
  • 823
  • 8
  • 19
  • 37

8 Answers8

29

Try below locator.

selenium.click("css=a[href*='listDetails.do'][id='oldcontent']");

or

selenium.click("xpath=//a[contains(@href,'listDetails.do') and @id='oldcontent']");
Santoshsarma
  • 5,627
  • 1
  • 24
  • 39
7

This works properly try this code-

selenium.click("xpath=//a[contains(@href,'listDetails.do') and @id='oldcontent']");
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
Aashi
  • 489
  • 1
  • 5
  • 12
3

This will get you the generic link:

selenium.FindElement(By.XPath("xpath=//a[contains(@href,'listDetails.do')")).Click();

If you want to have it specify a parameter then you will have to test for each one:

...
int i = 1;

selenium.FindElement(By.XPath("xpath=//a[contains(@href,'listDetails.do?camp=" + i.ToString() + "')")).Click();
...

The above could utilize a for loop which navigates to and from each camp numbers' page, which could verify a static list of camps.

Please excuse if the code is not perfect, I have not tested myself.

Mateut Alin
  • 1,173
  • 4
  • 17
  • 34
Mark
  • 31
  • 1
1

have you tried:

//a[@id='oldcontent']/u[text()='Re-Call']
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
Nora
  • 1,432
  • 8
  • 9
1

for me worked //a[text()='Re-Call']

1

what worked for me:

//a[contains(@href,'logout')]
vlatko606
  • 909
  • 1
  • 13
  • 21
0

Below works fine.

//a[@id='oldcontent']

If you've tried certain ones and they haven't worked, then let us know, otherwise something simple like this should work.

Arran
  • 24,648
  • 6
  • 68
  • 78
  • There are multiple tags with same id,so am not using that.i want to pick it up using href value itself – cxyz Oct 29 '12 at 15:54
  • selenium.click("css=a[href='listDetails.do?camp=236767']"); also does not work :-( – cxyz Oct 29 '12 at 15:56
  • 2
    OK, what about `//a[@href='listDetails.do?camp=1865']`, note that it looks like the integer at the end is a unique ID, so you will need to cater for this. Do you get the element returned if you do a blanket contains search? `//a[contains(@href, 'listDetails.do')]` – Arran Oct 29 '12 at 15:58
  • Yes i need to pick up based on the unique id at the end of the listDetails.do?camp=1865,since all hrefs have sommon string listDetails.do?camp..Only integer differs – cxyz Oct 29 '12 at 16:00
  • selenium.click("xpath=//a[@href='listDetails.do?camp=1865']"); does not work..Can anyone suggest solution – cxyz Oct 29 '12 at 16:07
  • 1
    What browser do you use? Works fine using Chrome v22. Does it find the element at all or just not click on it? – Arran Oct 29 '12 at 16:15
  • Am using IE8.may be its not finding the element – cxyz Oct 29 '12 at 16:40
  • Have you set up IE8 according to: https://code.google.com/p/selenium/wiki/InternetExplorerDriver (the 'Required Configuration' section) – Arran Oct 30 '12 at 09:29
  • FYI if there are multiple elements with the same ID then you have a bigger issue as you have invalid elements. If you have any JavaScript code on the page calling `document.getElementById(id);` you will get inconsistent results depending on the browser/version. I would **HIGHLY** recommend fixing the invalid DOM first. – scunliffe Oct 30 '12 at 15:55
0

Best way to locate anchor elements is to use link=Re-Call:

selenium.click("link=Re-Call");

It will work..

A.D.
  • 4,487
  • 3
  • 38
  • 50
Virendra Joshi
  • 469
  • 4
  • 8
  • 25