Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the second element that has the same class name in selenium using java

When trying to automate our application, there are two buttons with same name.

I'm not able to find a way to recognize these. Please let me know what could be the other ways to identify these elements in selenium webdriver in java

like image 945
Nagarjuna Reddy Avatar asked May 23 '14 12:05

Nagarjuna Reddy


People also ask

How do you get the second element with the same class name in Selenium?

Answers 1 : of How to access the second element that has the same class name in selenium using java. You can use xpath indexing option.

How do you find all elements with the same class in Selenium?

We can get text from multiple elements with the same class in Selenium webdriver. We have to use find_elements_by_xpath(), find_elements_by_class_name() or find_elements_by_css_selector() method which returns a list of all matching elements.

Where is the second element in Selenium?

findElements(By. linkText("Services"));; li. get(1). click();//If there are only two such element, here 1 is index of 2nd element in list returned.


1 Answers

You can use xpath indexing option.

By.xpath("(//input[@name='Button'])[2]")
like image 126
Santoshsarma Avatar answered Sep 19 '22 20:09

Santoshsarma