Share
Go down
balakrishna
Posts : 2
Join date : 2014-04-03

how to identify element using xpath having same class names?

on Tue Apr 22, 2014 1:29 am
Example: "html/body/form/table[3]/tbody/tr/td[2]/input"

In the above example td[2] has two same class names as mybutton1 for two different buttons ( save and Next). Can any one help me how can i identify the these buttons? I tried it with above example and it is picking up Save button.
avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: how to identify element using xpath having same class names?

on Tue Jun 24, 2014 6:00 pm
hi,
use index value instead of class name 
html/body/form/table[3]/tbody/tr/td[2]/input[1] for save
html/body/form/table[3]/tbody/tr/td[2]/input[2] for cancel

_________________
Spread Your Knowledge About Selenium Tool.

Administrator
Email: selenium.discussion.thread@live.com
Forum: http://seleniumforum.forumotion.net
ravindarreddy.nalla
Posts : 5
Join date : 2014-07-19

Re: how to identify element using xpath having same class names?

on Sat Jul 19, 2014 12:51 am
Hi BalaKrishna.

Don't use indexes, Object identification failed if another object is added in between objects. Try below code if not works let me know the same.

Code:
Driver.findElements(By.xpath("//input[text()='Save']"));
Driver.findElements(By.xpath("//input[text()='Cancel']"));
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

Re: how to identify element using xpath having same class names?

on Tue Jul 22, 2014 4:16 pm
I think it is
Code:
driver.findElement

rather than
Code:
driver.findElements
ravindarreddy.nalla
Posts : 5
Join date : 2014-07-19

Re: how to identify element using xpath having same class names?

on Wed Jul 23, 2014 1:44 pm
Yes Prassad. It is webelement we need to use driver.findElement only
nabhanya.varma
Active particpant
Active particpant
Posts : 13
Join date : 2014-03-02

Re: how to identify element using xpath having same class names?

on Sat Sep 13, 2014 5:25 pm
hi, try using relative xpath instead of using absolute xpath.
 Relative xpath is one where the path starts from the node of your choise - it doesn't need to start from the root node.
It starts with Double forward slash(//)
For more.. Please visit
http://www.seleniumeasy.com/selenium-tutorials/xpath-tutorial-for-selenium
Sponsored content

Re: how to identify element using xpath having same class names?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum