Two links with same name

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Two links with same name

MadrasMozart
Hi ,

I have a web application where there are two links with same name.
When i use
driver.findElement(By.linkText("Travel and Expense Center")).click();
i get error stating there is no webelement.

i tried using xpath

driver.findElement(By.xpath("//A[@class='PTNAVLINK' and @name='EP_SC_SP_EMPLOYEE_TE_CENTER']")).click();

for this also i am getting the same error.

the difference between the two links with same are their class property...

can you please advice ?
Reply | Threaded
Open this post in threaded view
|

Re: Two links with same name

softwaretestingforum
Administrator
Can you post the short html of those elements?
Also the entire stack trace of error you encounter.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Two links with same name

Illusion0Reality
In reply to this post by MadrasMozart
I have seen some where, using [2] (indicates that should click on the 2nd element that have same names) with the above syntax.

Can you try that.

driver.findElement(By.xpath("//A[@class='PTNAVLINK' and @name='EP_SC_SP_EMPLOYEE_TE_CENTER']")).click();
Reply | Threaded
Open this post in threaded view
|

Re: Two links with same name

Illusion0Reality
In reply to this post by MadrasMozart
I created exactly 2 text boxes with same properties. And the below code worked fine:

        selenium.type("xpath=(//input[@id='mt'])[2]", "888");
        selenium.type("xpath=(//input[@id='mt'])[1]", "111");
               

In the above, the [2] refers to the second element on the screen.