Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath for href element

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?Thanks in advance for help

like image 420
cxyz Avatar asked Oct 29 '12 15:10

cxyz


People also ask

How href link to XPath?

This will get you the generic link: selenium. FindElement(By. XPath("xpath=//a[contains(@href,'listDetails.do')")).

How do I find the XPath of a link?

Launch the Chrome browser and navigate to the URL or webpage. Hover the mouse over the desired element (object) on the web page, right-click on the element you are looking for XPath, and select “Inspect.”

How do you find the href of an element?

Use the querySelector() method to get an element by an href attribute, e.g. document. querySelector('a[href="https://example.com"]') . The method returns the first element that matches the selector or null if no element with the provided selector exists in the DOM.

How do I select a href in Selenium?

We can click a href link with Selenium webdriver. There are multiple ways to achieve this. First of all we need to identify the link with the help of the locators like link text and partial link text. The link text locator identifies the element whose text matches with text enclosed within the anchor tag.


2 Answers

Try below locator.

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

or

selenium.click("xpath=//a[contains(@href,'listDetails.do') and @id='oldcontent']");
like image 72
Santoshsarma Avatar answered Sep 29 '22 13:09

Santoshsarma


This works properly try this code-

selenium.click("xpath=//a[contains(@href,'listDetails.do') and @id='oldcontent']");
like image 34
Aashi Avatar answered Sep 29 '22 13:09

Aashi